[R] calling self written R functions

2011-11-17 Thread Sachinthaka Abeywardana
Hi All,

I have written a function (say) called foo, saved in a file called
foo.R. Just going by Matlab syntax I usually just change my folder path and
therefore can call it at will.

When it comes to R, how is the usual way of calling/loading it? because R
doesnt seem to automatically find the function from a folder (which might
be stupid to attempt in the first place).

Thanks,
Sachin

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] calling self written R functions

2011-11-17 Thread Joshua Wiley
Hi Sachin,

Nope, R does not work that way.  You do have several options, though.
For a function or two, consider creating/editing a workspace .Rprofile
file.

https://www.google.com/?q=Rprofile

should bring up a fair number of pages describing this, you might look at a few.

If you find yourself getting a little collection of functions, with
some of them possibly depending on each other, and/or wanting to have
documentation for your function(s), it is time to write a package.
There was a nice video tutorial of this at the LA R User Group meeting
not too long ago, you can find it here:
http://www.youtube.com/watch?v=TER-rQoVs0k
You can also see the official manual on extensions for how to write
packages: http://cran.r-project.org/doc/manuals/R-exts.html

Cheers!

Josh

On Thu, Nov 17, 2011 at 5:26 PM, Sachinthaka Abeywardana
sachin.abeyward...@gmail.com wrote:
 Hi All,

 I have written a function (say) called foo, saved in a file called
 foo.R. Just going by Matlab syntax I usually just change my folder path and
 therefore can call it at will.

 When it comes to R, how is the usual way of calling/loading it? because R
 doesnt seem to automatically find the function from a folder (which might
 be stupid to attempt in the first place).

 Thanks,
 Sachin

        [[alternative HTML version deleted]]

 __
 R-help@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.




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/

__
R-help@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.


Re: [R] calling self written R functions

2011-11-17 Thread Sarah Goslee
?source

source(/path/to/foo.R) will load it into R.

Sarah

On Thu, Nov 17, 2011 at 8:26 PM, Sachinthaka Abeywardana
sachin.abeyward...@gmail.com wrote:
 Hi All,

 I have written a function (say) called foo, saved in a file called
 foo.R. Just going by Matlab syntax I usually just change my folder path and
 therefore can call it at will.

 When it comes to R, how is the usual way of calling/loading it? because R
 doesnt seem to automatically find the function from a folder (which might
 be stupid to attempt in the first place).

 Thanks,
 Sachin



-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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.


Re: [R] calling self written R functions

2011-11-17 Thread Sachinthaka Abeywardana
Looks like the function I was looking for was source(), but thanks Joshua I
certainly do need to make a package once I finish this set of re-coding
into R from Matlab. Fingers crossed the effort is worth it.

Thanks,
Sachin

On Fri, Nov 18, 2011 at 1:34 PM, Sarah Goslee sarah.gos...@gmail.comwrote:

 ?source

 source(/path/to/foo.R) will load it into R.

 Sarah

 On Thu, Nov 17, 2011 at 8:26 PM, Sachinthaka Abeywardana
 sachin.abeyward...@gmail.com wrote:
  Hi All,
 
  I have written a function (say) called foo, saved in a file called
  foo.R. Just going by Matlab syntax I usually just change my folder path
 and
  therefore can call it at will.
 
  When it comes to R, how is the usual way of calling/loading it? because R
  doesnt seem to automatically find the function from a folder (which might
  be stupid to attempt in the first place).
 
  Thanks,
  Sachin
 


 --
 Sarah Goslee
 http://www.functionaldiversity.org


[[alternative HTML version deleted]]

__
R-help@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.