Re: [R] Good Programming Practice Question - Functions in Different Files

2009-06-09 Thread Paul Hiemstra

Hi,

I always use source for this kinds of things. If you have a lot of code, 
you could consider wrapping it into an R-package. This would allow you 
to load all the code by using the library(myPackage) command. But this 
might be unnecessary for your situation.


cheers,
Paul

Jason Rupert wrote:

I've gotten to the point wih an R script where I would like to encapsulate 
several blocks of codes in R functions.

In order to keep the top level script simple I would like to put them in a 
separate file.  This should help the readability of the top level main script.

Is source(...) the best way to load those functions in the top level script?  


For example, in the top level script
Line#
01  source(FunctionsFile.R)
02
03  callfunctionfromfunctionfile(...)

Thanks for any feedback and insights. 


Also, I found the following:
http://www.stat.auckland.ac.nz/~paul/ItDT/HTML/node71.html

But are there other guides out there that speak to good practices when 
developing in R?

__
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.
  



--
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone:  +3130 274 3113 Mon-Tue
Phone:  +3130 253 5773 Wed-Fri
http://intamap.geo.uu.nl/~paul

__
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] Good Programming Practice Question - Functions in Different Files

2009-06-09 Thread spencerg
Sundar Dorai-Raj taught me to do the following: 



   Rdir - c:\appropriatepath\R

   Rfiles - dir(Rdir, pattern='\\.R$', full.names=TRUE)

   invisible(lapply(aTR, source))


 The invisible suppresses the garbage while still displaying 
error messages. 



 Hope this helps. 
 Spencer   



Paul Hiemstra wrote:

Hi,

I always use source for this kinds of things. If you have a lot of 
code, you could consider wrapping it into an R-package. This would 
allow you to load all the code by using the library(myPackage) 
command. But this might be unnecessary for your situation.


cheers,
Paul

Jason Rupert wrote:
I've gotten to the point wih an R script where I would like to 
encapsulate several blocks of codes in R functions.


In order to keep the top level script simple I would like to put them 
in a separate file.  This should help the readability of the top 
level main script.


Is source(...) the best way to load those functions in the top level 
script? 
For example, in the top level script

Line#
01  source(FunctionsFile.R)
02
03  callfunctionfromfunctionfile(...)

Thanks for any feedback and insights.
Also, I found the following:
http://www.stat.auckland.ac.nz/~paul/ItDT/HTML/node71.html

But are there other guides out there that speak to good practices 
when developing in R?


__
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.
  





__
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] Good Programming Practice Question - Functions in Different Files

2009-06-09 Thread Henrik Bengtsson
library(R.utils);
sourceDirectory(C:/appropriatepath/R/, modifiedOnly=TRUE);


On Tue, Jun 9, 2009 at 8:09 PM, spencergspencer.gra...@prodsyse.com wrote:
 Sundar Dorai-Raj taught me to do the following:

           Rdir - c:\appropriatepath\R

           Rfiles - dir(Rdir, pattern='\\.R$', full.names=TRUE)

           invisible(lapply(aTR, source))


     The invisible suppresses the garbage while still displaying error
 messages.

     Hope this helps.     Spencer

 Paul Hiemstra wrote:

 Hi,

 I always use source for this kinds of things. If you have a lot of code,
 you could consider wrapping it into an R-package. This would allow you to
 load all the code by using the library(myPackage) command. But this might be
 unnecessary for your situation.

 cheers,
 Paul

 Jason Rupert wrote:

 I've gotten to the point wih an R script where I would like to
 encapsulate several blocks of codes in R functions.

 In order to keep the top level script simple I would like to put them in
 a separate file.  This should help the readability of the top level main
 script.

 Is source(...) the best way to load those functions in the top level
 script? For example, in the top level script
 Line#
 01  source(FunctionsFile.R)
 02
 03  callfunctionfromfunctionfile(...)

 Thanks for any feedback and insights.
 Also, I found the following:
 http://www.stat.auckland.ac.nz/~paul/ItDT/HTML/node71.html

 But are there other guides out there that speak to good practices when
 developing in R?

 __
 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.




 __
 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.


__
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.