hello, i have a couple of .R files distributed about my file system. i commonly source() these from other files, but i have to include the full file path. this is not always convenient if you move files around. is there a way of setting the search path for source()? thanks a lot! cheers, andrew. -- Andrew B. Collier Space Physics Group Hermanus Magnetic Observatory Honorary Research Fellow tel: +27 31 2601157 Space Physics Research Institute fax: +27 31 2616550 University of KwaZulu-Natal, Durban, 4041, South Africa gsm: +27 83 3813655
Here is the discussion about the function search.path() http://finzi.psych.upenn.edu/R/Rhelp02a/archive/34411.html which searches the PATH variable for your script and returns the full path. You also can put your script contents in functions, then create a package and load it with library(). package.skeleton() can help you. Anyway, source()'ing every time does not seem to be a good idea, because every time you do this you obtain one more copy of your functions and variables in the newly created workspace. If you don't want to create a package, you can save your functions in a file with the .Rdata extension and attach that file. Try going here https://www.stat.math.ethz.ch/pipermail/r-help/2004-July/thread.html and searching "source()" in the page (i.e. in message headers). I believe, discussions could provide you with several more good ideas. colliera wrote:> > i have a couple of .R files distributed about my file system. i commonly > source() these from other files, but i have to include the full file path. > this is not always convenient if you move files around. is there a way of > setting the search path for source()? >-- View this message in context: http://www.nabble.com/-R--path-for-source%28%29-tf3191709.html#a8861457 Sent from the R help mailing list archive at Nabble.com.
Hi, an easy way to address this is to change directory within R before calling source() : setwd("D:/Projects/yourProject") source("yourCode.R") Of course you need to know where your .R files are. Using getwd() you can always check where you are and using dir() you can check the files in your directory (which you could combine with grep() to search for ".R") .. Wolfgang colliera at ukzn.ac.za a ?crit :> hello, > > i have a couple of .R files distributed about my file system. i commonly source() these from other files, but i have to include the full file path. this is not always convenient if you move files around. is there a way of setting the search path for source()? > > thanks a lot! > > cheers, > andrew. > >-- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Wolfgang Raffelsberger, PhD Laboratoire de BioInformatique et G?nomique Int?grative IGBMC 1 rue Laurent Fries, 67404 Illkirch Strasbourg, France Tel (+33) 388 65 3300 Fax (+33) 388 65 3276 wolfgang.raffelsberger at igbmc.u-strasbg.fr
Maybe Matching Threads
- NaN with ccf() for vector with all same element
- problem with compilation of R on Solaris 10 in x86
- Package RODBC
- alternatives to traditional least squares method in linear regression ?
- how to make a function recognize the name of an object/vector given as argument