[R] Problem in loading all packages all at once

Charilaos Skiadas skiadas at hanover.edu
Mon Mar 26 14:34:18 CEST 2007


A couple of things:

1) It would have been a lot easier to help you if you had created a  
much smaller example. perhaps trying to load 2-3 packages instead of  
1000. Now we have to wade through a lot of stuff to get to the point.

2) Perhaps your call to Sys.putenv doesn't do quite what you expect  
it to do. Example:
 > TEMP <- c("a","b")
 > Sys.getenv("TEST")
TEST
   ""
 > Sys.putenv(TEST=TEMP)
 > Sys.getenv("TEST")
TEST
"b"

3) I couldn't really see where in your code all these packages are  
loaded. Reading the help for .First.sys tells me that that's the call  
that actually loads the default packages, unless I've misunderstood  
something. If that's the case, then the following line you have at  
the end would prevent this loading:

.First.sys <- function()


I must say that from the ?Startup help there are two things that are  
not very clear:
a) At what point in the load process is R_DEFAULT_PACKAGES  
checked? .First.sys doesn't seem to know about it.
Ok, a bit of search provided an answer to this: Reading the help for  
"options", I see there, in the section about defaultPackages, what is  
probably the most helpful bit (for me) in all this:

defaultPackages:
	the packages that are attached by default when R starts up.  
Initially set from value of the environment variable  
R_DEFAULT_PACKAGES, or if that is unset to c("datasets", "utils",  
"grDevices", "graphics", "stats", "methods"). (Set R_DEFAULT_PACKAGES  
to NULL or a comma-separated list of package names.) A call to  
options should be in your ‘.Rprofile’ file to ensure that the change  
takes effect before the base package is initialized (see Startup).

	
b) What is the format that the R_DEFAULT_PACKAGES variable must have  
(I guess now I know, since it is mentioned in ?options, though that's  
not really the place I would have expected it to be explained) ? The  
only examples I could find on the web were setting it to NULL.



Hope all this helps in some way.

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College


On Mar 26, 2007, at 6:01 AM, gyadav at ccilindia.co.in wrote:

>
> Hi All
>
> Please see the Rprofile file which i have modified as follows and  
> after
> that when I start R then I see that R says to me "TRUE" for all the
> packages implying that all loaded at once.
> But when i try to use commands as simple as help("lm"), it doesnt  
> work nor
> any of the menu "Packages" is not working.
> Although the regression using lm ( Y ~ X ) is working even summary and
> rnorm is working fine.
> Please tell me why menu and help command is not working
>
> Rprofile is in between +++++++++++++++++++++++++++ lines
> R initialization is in between @@@@@@@@@@@@@@ lines
> Commands are in between $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ lines
>
> Please also suggest me should i send this to r-devel list or not
>
> ### This is the system Rprofile file. It is always run on startup.
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
> ++++
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
> ++++
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
> ++++
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
> ++++
> options(scipen = 0)
> options(max.print = 10000)# not yet exercised in 'core R'
> options(add.smooth = TRUE)# currently only used in 'plot.lm'
>
> ###################################################################### 
> ########################
> ###################################################################### 
> ########################
> #############code added by gaurav yadav to install many other  
> packages at
> startup#############
> print ("START OF CODE ADDED BY GAURAV YADAV")
> TEMP <- Sys.getenv("R_DEFAULT_PACKAGES")
> print ("R_DEFAULT_PACKAGES")
> print (TEMP)
> print ("=======")
> TEMP <-
> c 
> (TEMP,"aplpack","approximator","apTreeshape","ArDec","arules","ash","a 
> space","assist","aster","asypow","aws","base","bayesm","bayesmix","bay 
> esSurv","BayesTree","BayesValidate","betareg","Bhat","BHH2","bicreduc" 
> ,"biglm","bim","bindata","Biodem","biopara","bitops","bivpois","blight 
> y","blockrand","BMA","boa","Bolstad","boolean","boost","boot","bootstr 
> ap","bqtl","BradleyTerry","brlr","BRugs","BSDA","BsMD","butler","calib 
> rate","calibrator","caMassClass","car","cat","caTools","catspec","cba" 
> ,"cclust","CDNmoney","cfa","CGIwithR","changeLOS","chplot","chron","Ci 
> rcStats","circular","clac","class","classInt","classPP","clim.pact","c 
> limatol","clines","clue","cluster","clusterRepro","clustvarsel","cmprs 
> k","cobs","CoCo","CoCoCg","CoCoCore","CoCoGraph","CoCoObjects","CoCoOl 
> dData","CoCoRaw","cocorresp","coda","coin","colorspace","combinat","co 
> mpositions","concor","concord","cond","conf.design","connectedness","c 
> opula","corpcor","corpora","covRobust","coxrobust","cramer","crossdes" 
> ,"crq","c
>  sampling","cslogistic","CTFS","ctv")
>
[snip]
> #TEMP <- c(TEMP,"runfirst","base","datasets", "utils", "grDevices",
> "graphics","stats","methods","lmtest")
> print ("MODIFIED R_DEFAULT_PACKAGES+++++++++++")
> print (TEMP)
> print ("++++++++++++++++")
> print(Sys.putenv(R_DEFAULT_PACKAGES=TEMP))
> print ("END OF CODE ADDED BY GAURAV YADAV")
>
> ###################################################################### 
> ########################
> ###################################################################### 
> ########################
>
>
> local({dp <- as.vector(Sys.getenv("R_DEFAULT_PACKAGES"))
>        if(identical(dp, "")) # marginally faster to do methods last
>            dp <- c("datasets", "utils", "grDevices", "graphics",
>                    "stats", "methods")
>        else if(identical(dp, "NULL")) dp <- character(0)
>        else dp <- strsplit(dp, ",")[[1]]
>        dp <- sub("[[:blank:]]*([[:alnum:]]+)", "\\1", dp) # strip
> whitespace
>        options(defaultPackages = dp)
>     })
>
> .First.sys <- function()
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
> ++++
>
> THE R SHOWS ME THIS GIVEN HEREIN BELOW WHEN I START R
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> [1] "START OF CODE ADDED BY GAURAV YADAV"
> [1] "R_DEFAULT_PACKAGES+++++++++++"
> R_DEFAULT_PACKAGES
>                 ""
> [1] "++++++++++++++++"
> [1] "MODIFIED R_DEFAULT_PACKAGES+++++++++++"
>   R_DEFAULT_PACKAGES
>                   ""            "aplpack"       "approximator"
>
>
[snip tons of packages]
> [1] "++++++++++++++++"
>   [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
> TRUE TRUE
> [751] TRUE TRUE TRUE TRUE TRUE TRUE TRUE
> [1] "END OF CODE ADDED BY GAURAV YADAV"
>
> R : Copyright 2006, The R Foundation for Statistical Computing
> Version 2.3.0 (2006-04-24)
> ISBN 3-900051-07-0
>
> R is free software and comes with ABSOLUTELY NO WARRANTY.
> You are welcome to redistribute it under certain conditions.
> Type 'license()' or 'licence()' for distribution details.
>
>   Natural language support but running in an English locale
>
> R is a collaborative project with many contributors.
> Type 'contributors()' for more information and
> 'citation()' on how to cite R or R packages in publications.
>
> Type 'demo()' for some demos, 'help()' for on-line help, or
> 'help.start()' for an HTML browser interface to help.
> Type 'q()' to quit R.
>
> [Previously saved workspace restored]
>
>>
>
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
>
> $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
>
> Type 'demo()' for some demos, 'help()' for on-line help, or
> 'help.start()' for an HTML browser interface to help.
> Type 'q()' to quit R.
>
> [Previously saved workspace restored]
>
>> help("lm")
> Error: could not find function "help"
>> help.search("regression")
> Error: could not find function "help.search"
>> local({pkg <- select.list(sort(.packages(all.available = TRUE)))
> + if(nchar(pkg)) library(pkg, character.only=TRUE)})
> Error in eval(expr, envir, enclos) : could not find function  
> "select.list"
>> chooseCRANmirror()
> Error: could not find function "chooseCRANmirror"
>> setRepositories()
> Error: could not find function "setRepositories"
>> utils:::menuInstallPkgs()
> --- Please select a CRAN mirror for use in this session ---
> Error in open.connection(file, "r") : unable to open connection
> In addition: Warning message:
> unable to connect to 'cran.r-project.org' on port 80.
> Error in contrib.url(repos, type) : trying to use CRAN without  
> setting a
> mirror
>> update.packages(ask='graphics')
> Error: could not find function "update.packages"
>> utils:::menuInstallLocal()
> Error in install.packages(choose.files("", filters = Filters[c 
> ("zip",  :
>         no packages were specified
>> X<-rnorm(1000)
>> Y<-rnorm(1000)
>> result<-lm(Y ~ X)
>> summary(result)
>
> Call:
> lm(formula = Y ~ X)
>
> Residuals:
>     Min      1Q  Median      3Q     Max
> -3.0047 -0.7205  0.0203  0.7232  3.1052
>
> Coefficients:
>               Estimate Std. Error t value Pr(>|t|)
> (Intercept)  0.0347667  0.0322268   1.079    0.281
> X           -0.0009727  0.0320626  -0.030    0.976
>
> Residual standard error: 1.018 on 998 degrees of freedom
> Multiple R-Squared: 9.223e-07,  Adjusted R-squared: -0.001001
> F-statistic: 0.0009204 on 1 and 998 DF,  p-value: 0.9758
>
>>
>
> $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$



More information about the R-help mailing list