[R] To define a function which includes two functions as arguments such as "plot" and "text"

Uwe Ligges ligges at statistik.tu-dortmund.de
Wed Feb 29 18:48:14 CET 2012



On 28.02.2012 07:04, Yashwanth M.R wrote:
> Hi  Mr. Uwe Ligges,

Yashwanth M.R,

this is the R-help mailing list, not my personal mail account (and "Mr." 
is inappropriate in any case).


>
>
>                  I really thankful for the reply.  I even tried the same,
> means writing the new function. But the result is same as the last. Here is
> the picture below,
>
>
>
>
>
>              Telco.Rpart.PLOT.TEXT.Functn<-
> function(Telco.Rpart.METHOD.CLASS)
>
>                          {
>
>                          Telco.Rpart.PLOT<-
> plot(Telco.Rpart.METHOD.CLASS,compress=FALSE,uniform=TRUE)
>
>                          Telco.Rpart.TEXT<-
> text(Telco.Rpart.METHOD.CLASS,use.n = TRUE, cex = .75)
>
>                          }
>
>
>
>    Telco.Rpart.PLOT.TEXT<-
> Telco.Rpart.PLOT.TEXT.Functn(Telco.Rpart.METHOD.CLASS)
>
> Telco.Rpart.PLOT.TEXT
>
>
>
>
>
> Again if I solely run the command "Telco.Rpart.PLOT.TEXT",

That is the value returned from the previous function call, not a 
command nor a function.


> the output it is
> displaying as "NULL". Please help me finding out the desired result ASAP.

Yes, since that ws the result of calling the previous function.

Your output is not reproducible hence it is hard to help for us, we do 
not really understand what you are going to do with functions, and you 
should start reading "An Introduction to R" in order to get a basic 
sense of R. Finally, this is a mailning list driven by volunteers, and 
sense some rudeness in demanding things "ASAP".

Best,
Uwe Ligges




>
>
>
>
> Regards,
>
> Yashwanth M.R
>
>
>
>
>
>
>
> From: Uwe Ligges-3 [via R] [mailto:ml-node+s789695n4417618h61 at n4.nabble.com]
>
> Sent: Friday, February 24, 2012 9:16 PM
> To: Yashwanth M.R
> Subject: Re: To define a function which includes two functions as arguments
> such as "plot" and "text"
>
>
>
>
>
> On 24.02.2012 12:22, Yashwanth M.R wrote:
>
>
>> Here is the two functions which I have used during my practice.
>>
>> *plot(Telco.rpart.METHOD.CLASS,compress=FALSE,uniform=TRUE)
>>
>> text(Telco.rpart.METHOD.CLASS,use.n = TRUE, cex = .75))*
>>
>> "Telco.rpart.METHOD.CLASS" is my "rpart" object of the method "class".
>>
>> If I run this,
>>
>> *Telco.Rpart.PLOT.TEXT<-
>> c(plot(Telco.rpart.METHOD.CLASS,compress=FALSE,uniform=TRUE),
>>                      text(Telco.rpart.METHOD.CLASS,use.n = TRUE, cex =
>> .75))
>
>
>
> c() concatenates the returned values of the two functions. If you want
> to define a sequence of function calls, define them within your own
> function, calling that new function will produce your desired results,
> as far as I understand.
>
> Uwe Ligges
>
>
>>
>> http://r.789695.n4.nabble.com/file/n4416881/Rpart.gif
>>
>> the output is getting generated as shown in the figure. But if I solely
> run
>> the same command "Telco.Rpart.PLOT.TEXT" right after the above, the output
>
>> is as below,
>>
>> /$x
>>    [1]  4.035156  1.000000  7.070312  3.015625  2.000000  4.031250
>>    [7]  3.000000  5.062500  4.000000  6.125000  5.000000  7.250000
>> [13]  6.500000  6.000000  7.000000  8.000000 11.125000 10.250000
>> [19]  9.500000  9.000000 10.000000 11.000000 12.000000
>>
>> $y
>>    [1] 1.125 1.000 1.000 0.875 0.750 0.750 0.625 0.625 0.500 0.500 0.375
>> [12] 0.375 0.250 0.125 0.125 0.250 0.875 0.750 0.625 0.500 0.500 0.625
>> [23] 0.750
>> /
>>
>>
>> Please help me in getting the output which is there is the Image..
>>
>> Regards,
>> Yashwanth M,R
>>
>> --
>> View this message in context:
> http://r.789695.n4.nabble.com/To-define-a-function-which-includes-two-functi
> ons-as-arguments-such-as-plot-and-text-tp4416881p4416881.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
>    _____
>
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://r.789695.n4.nabble.com/To-define-a-function-which-includes-two-functi
> ons-as-arguments-such-as-plot-and-text-tp4416881p4417618.html
>
> To unsubscribe from To define a function which includes two functions as
> arguments such as "plot" and "text", click here
> <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by
> _code&node=4416881&code=eWFzaHdhbnRoQHByZWRpY3RpdmVhbmFseXRpY3MuaW58NDQxNjg4
> MXwyOTE4OTgwMjc=>  .
>
> <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&i
> d=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamesp
> ace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNa
> mespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%
> 21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>  NAML
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/To-define-a-function-which-includes-two-functions-as-arguments-such-as-plot-and-text-tp4416881p4427151.html
> Sent from the R help mailing list archive at Nabble.com.
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list