In the context of calling R from another program (namely gretl, http://gretl.sourceforge.net ) I'm trying to understand the interactions of the R init file (corresponding to the environment variable RPROFILE) and the source() function.
I'll illustrate my problem with the following simplified contrast implemented in the bash shell (with R 2.7.1). 1. Works fine: [EMAIL PROTECTED]:~/Rfoo$ cat fooProfile1 # nothing here [EMAIL PROTECTED]:~/Rfoo$ cat doit.1 export RPROFILE="fooProfile1" R --no-save --no-init-file --no-restore-data --slave <fooSrc [EMAIL PROTECTED]:~/Rfoo$ cat fooSrc library(graphics) postscript("myfile.ps") [EMAIL PROTECTED]:~/Rfoo$ sh doit.1 (silently produces a well-formed but empty myfile.ps) 2. Doesn't work: [EMAIL PROTECTED]:~/Rfoo$ cat fooProfile2 source("fooSrc", verbose=TRUE, echo=TRUE) [EMAIL PROTECTED]:~/Rfoo$ cat doit.2 export RPROFILE="fooProfile2" R --no-save --no-init-file --no-restore-data --slave [EMAIL PROTECTED]:~/Rfoo$ cat fooSrc library(graphics) postscript("myfile.ps") [EMAIL PROTECTED]:~/Rfoo$ sh doit.2 'envir' chosen:<environment: R_GlobalEnv> encoding = "native.enc" chosen --> parsed 2 expressions; now eval(.)ing them: >>>> eval(expression_nr. 1 ) ================= > library(graphics) curr.fun: symbol library .. after `expression(library(graphics))' >>>> eval(expression_nr. 2 ) ================= > postscript("myfile.ps") Error in eval.with.vis(expr, envir, enclos) : could not find function "postscript" == end of output == I'd like to understand why, after loading the graphics library, the function postscript() is not available in the second case while it is in the first. (The file fooSrc has the same content in the two cases: in the first case it's loaded via the shell, while in the second it's loaded using R's source() function.) Thanks for any help. -- Allin Cottrell Department of Economics Wake Forest University, NC ______________________________________________ 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.