RE: [R] how to define functions in such a situation

From: Liaw, Andy <andy_liaw_at_merck.com>
Date: Tue 07 Jun 2005 - 23:09:34 EST


It't not clear to me exactly what you want and how you envision it could be done, but it probably helps to realize that functions in R (and S in general) are first class objects, so you can manipulate them pretty much like any other objects. You can "compute" them "on-the-fly", e.g., by having a fuction returning a function (or a list of functions). I find reading the Language Definition manual very helpful for things like this.

As an example, the ecdf() function returns a function that can compute the estimated ecdf for any input. There may be simpler examples elsewhere.

Andy

> From: Hu Chen
>
> hi R folks,
> I need read a file from hardisk or www web. Then I need to define some
> new functions according to the contents of the read file.
> For example, i need write a package name "mypackage" like this:
> >library(mypackage)
> >read(some_file_on_web) #to see its content, suppose it contains:
> eat.drink.sleep
> then 3 new functions need to be created and usable.
> the problem is, how could I create functions after executing
> ">library(mypackage)" and make these new functions visible and usable
> immediately?
>
> Any information are appreciated. forgive me if this question is very
> stupid. but I really need help.
> Thank you all.
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jun 07 23:27:52 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:26 EST