Re: [R] Rprofile.site and automatic installation of missing packages
Hallo Duncan Thanks for your hints, yes, the code in Rprofile.site is not executed. I am not sure, if I understood the startup mechanism correctly and I am a bit puzzled. Fresh installation (root C:Program files, write protected) has files Rprofile.site and .Rconsole installed in its etc directory. After starting R I can see that home directory is > Sys.getenv("R_USER") [1] "srvudst01.precheza.cz\\userdata\\PikalP\\Dokumenty" .Rconsole or .Rprofile in this directory are executed but Rprofile.site located in this directory is not. After fresh R installation to set all users to have the same startup I have two options: Change Rprofile.site in ...R\etc directory Put the same .Rprofile file into R_Home directory for each user Am I right or are there any other options how to set R on startup for all users differently from factory fresh setting? Sorry for my questions, it is something I never done before but I now need to resolve it in a way which fits to our IT environment. Best regards. Petr -Original Message- From: Duncan Murdoch Sent: Tuesday, March 21, 2023 5:43 PM To: PIKAL Petr ; r-help Subject: Re: [R] Rprofile.site and automatic installation of missing packages On 21/03/2023 9:58 a.m., PIKAL Petr wrote: > Hallo Duncan > > Tested but does not work so something other must be wrong. > > R version 4.2.2. >> installed.packages()[,"Package"] >base boot classcluster codetools > compiler datasetsforeign graphics grDevices > grid KernSmooth > "base" "boot""class" "cluster""codetools" > "compiler" "datasets" "foreign" "graphics""grDevices" >"grid" "KernSmooth" > lattice MASS Matrixmethods mgcv > nlme nnet parallel rpartspatial > splines stats > "lattice" "MASS" "Matrix" "methods" "mgcv" > "nlme" "nnet" "parallel""rpart" "spatial" > "splines""stats" > stats4 survival tcltk tools translations >utils >"stats4" "survival""tcltk""tools" "translations" > "utils" > > My Rprofile.site > # Things you might want to change > options(papersize="a4") > options(help_type="html") > > library(utils) > library(MASS) > > #** > test <-(scan("pack.txt", character(), quote = "")) > x<- utils::installed.packages() > utils::install.packages(test[!test %in% x], > repos="https://cloud.r-project.org;) > > ##** > > Options are set and working. > MASS should be loaded but is not > >> search() > [1] ".GlobalEnv""package:stats" "package:graphics" > "package:grDevices" "package:utils" "package:datasets" "package:methods" > "Autoloads" "package:base" >> > > Any suggestion where to look? I'd add code to print the values of x and test to confirm that things are proceeding as you expect. I don't know if print() or cat() will work there; you might need to use message(). For attaching packages, you should see ?Startup again: this is done via options() or an environment variable, not library() calls in the profile file. Duncan Murdoch > > Best regards > Petr > > -Original Message- > From: Duncan Murdoch > Sent: Tuesday, March 21, 2023 1:55 PM > To: PIKAL Petr ; r-help > Subject: Re: [R] Rprofile.site and automatic installation of missing > packages > > ?Startup says: "Note that when the site and user profile files are sourced > only the base package is loaded, so objects in other packages need to be > referred to by e.g. utils::dump.frames or after explicitly loading the > package concerned." > > So you need utils::installed.packages and utils::install.packages . > > Duncan Murdoch > > On 21/03/2023 8:04 a.m., PIKAL Petr wrote: >> Dear all. >> >> >> >> I am trying to install missing (not installed) packages during >> startup of R through code in Rprofile.site but I miserably failed and >> I am not sure what I am doing wrong. >> >> >> >> R is installed to C:Program files but it i
Re: [R] Rprofile.site and automatic installation of missing packages
On 21/03/2023 9:58 a.m., PIKAL Petr wrote: Hallo Duncan Tested but does not work so something other must be wrong. R version 4.2.2. installed.packages()[,"Package"] base boot classcluster codetools compiler datasetsforeign graphics grDevices grid KernSmooth "base" "boot""class" "cluster""codetools" "compiler" "datasets" "foreign" "graphics""grDevices" "grid" "KernSmooth" lattice MASS Matrixmethods mgcv nlme nnet parallel rpartspatial splines stats "lattice" "MASS" "Matrix" "methods" "mgcv" "nlme" "nnet" "parallel""rpart" "spatial" "splines""stats" stats4 survival tcltk tools translations utils "stats4" "survival""tcltk""tools" "translations" "utils" My Rprofile.site # Things you might want to change options(papersize="a4") options(help_type="html") library(utils) library(MASS) #** test <-(scan("pack.txt", character(), quote = "")) x<- utils::installed.packages() utils::install.packages(test[!test %in% x], repos="https://cloud.r-project.org;) ##** Options are set and working. MASS should be loaded but is not search() [1] ".GlobalEnv""package:stats" "package:graphics" "package:grDevices" "package:utils" "package:datasets" "package:methods" "Autoloads" "package:base" Any suggestion where to look? I'd add code to print the values of x and test to confirm that things are proceeding as you expect. I don't know if print() or cat() will work there; you might need to use message(). For attaching packages, you should see ?Startup again: this is done via options() or an environment variable, not library() calls in the profile file. Duncan Murdoch Best regards Petr -Original Message- From: Duncan Murdoch Sent: Tuesday, March 21, 2023 1:55 PM To: PIKAL Petr ; r-help Subject: Re: [R] Rprofile.site and automatic installation of missing packages ?Startup says: "Note that when the site and user profile files are sourced only the base package is loaded, so objects in other packages need to be referred to by e.g. utils::dump.frames or after explicitly loading the package concerned." So you need utils::installed.packages and utils::install.packages . Duncan Murdoch On 21/03/2023 8:04 a.m., PIKAL Petr wrote: Dear all. I am trying to install missing (not installed) packages during startup of R through code in Rprofile.site but I miserably failed and I am not sure what I am doing wrong. R is installed to C:Program files but it is not writable for the users, therefore I cannot change Rprofile.site located in root etc directory. I however can put Rprofile.site in users home directory (Documents) and use it for R startup setting (partly). However I want for less experienced users to put a code here to check installed packages, check if some specified set of packages is installed and install them, but it is not working. The code in Rprofile.site is: #** test <- scan("pack.txt", character(), quote = "") inst <- installed.packages() install.packages(test[!test %in% inst], repos="https://cloud.r-project.org;) #** An example of pack.txt is e.g. ggplot2 zoo but the code is not executed and packages are not installed. If I use this code after R starts, everything is OK and packages are installed to Sys.getenv("R_LIBS_USER") [1] "C:\\Users\\PikalP\\AppData\\Local/R/win-library/4.2" The same applies if I put e.g. library(MASS) in the Rprofile.site, the package is not loaded but after R is live, library(MASS) loads a package. So my question is What is the best way to check after fresh R installation if some predefined set of packages is installed and if not, perform an installation without user intervention in Windows environment? S pozdravem | Best Regards Petr __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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. Osobní úd
Re: [R] Rprofile.site and automatic installation of missing packages
Hallo Duncan Tested but does not work so something other must be wrong. R version 4.2.2. > installed.packages()[,"Package"] base boot classcluster codetools compiler datasetsforeign graphics grDevices grid KernSmooth "base" "boot""class" "cluster""codetools" "compiler" "datasets" "foreign" "graphics""grDevices" "grid" "KernSmooth" lattice MASS Matrixmethods mgcv nlme nnet parallel rpartspatial splines stats "lattice" "MASS" "Matrix" "methods" "mgcv" "nlme" "nnet" "parallel""rpart" "spatial" "splines""stats" stats4 survival tcltk tools translations utils "stats4" "survival""tcltk""tools" "translations" "utils" My Rprofile.site # Things you might want to change options(papersize="a4") options(help_type="html") library(utils) library(MASS) #** test <-(scan("pack.txt", character(), quote = "")) x<- utils::installed.packages() utils::install.packages(test[!test %in% x], repos="https://cloud.r-project.org;) ##** Options are set and working. MASS should be loaded but is not > search() [1] ".GlobalEnv""package:stats" "package:graphics" "package:grDevices" "package:utils" "package:datasets" "package:methods" "Autoloads" "package:base" > Any suggestion where to look? Best regards Petr -Original Message- From: Duncan Murdoch Sent: Tuesday, March 21, 2023 1:55 PM To: PIKAL Petr ; r-help Subject: Re: [R] Rprofile.site and automatic installation of missing packages ?Startup says: "Note that when the site and user profile files are sourced only the base package is loaded, so objects in other packages need to be referred to by e.g. utils::dump.frames or after explicitly loading the package concerned." So you need utils::installed.packages and utils::install.packages . Duncan Murdoch On 21/03/2023 8:04 a.m., PIKAL Petr wrote: > Dear all. > > > > I am trying to install missing (not installed) packages during startup > of R through code in Rprofile.site but I miserably failed and I am not > sure what I am doing wrong. > > > > R is installed to C:Program files but it is not writable for the > users, therefore I cannot change Rprofile.site located in root etc > directory. I however can put Rprofile.site in users home directory > (Documents) and use it for R startup setting (partly). > > However I want for less experienced users to put a code here to check > installed packages, check if some specified set of packages is > installed and install them, but it is not working. > > > > The code in Rprofile.site is: > > > > #** > > test <- scan("pack.txt", character(), quote = "") > > inst <- installed.packages() > > install.packages(test[!test %in% inst], > repos="https://cloud.r-project.org;) > > #** > > > > An example of pack.txt is e.g. > > ggplot2 > > zoo > > > > but the code is not executed and packages are not installed. If I use > this code after R starts, everything is OK and packages are installed > to > > > >> Sys.getenv("R_LIBS_USER") > > [1] "C:\\Users\\PikalP\\AppData\\Local/R/win-library/4.2" > >> > > The same applies if I put e.g. library(MASS) in the Rprofile.site, the > package is not loaded but after R is live, library(MASS) loads a package. > > > > So my question is What is the best way to check after fresh R > installation if some predefined set of packages is installed and if > not, perform an installation without user intervention in Windows environment? > > > > S pozdravem | Best Regards > > Petr > > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. Osobní údaje: Informace o zpracování a ochraně
Re: [R] Rprofile.site and automatic installation of missing packages
Thanks Duncan I expected some silly mistake on my side. Just for completeness, I finally tested .Rprofile file with the code and it worked. So now the question is whether to use your suggestion or .Rprofile file way. I tend to use Rprofile.site way as it enables experienced users to modify their .Rprofile to get customised way how to start R. Best regards Petr > -Original Message- > From: Duncan Murdoch > Sent: Tuesday, March 21, 2023 1:55 PM > To: PIKAL Petr ; r-help > Subject: Re: [R] Rprofile.site and automatic installation of missing > packages > > ?Startup says: "Note that when the site and user profile files are sourced > only > the base package is loaded, so objects in other packages need to be referred > to > by e.g. utils::dump.frames or after explicitly loading the package > concerned." > > So you need utils::installed.packages and utils::install.packages . > > Duncan Murdoch > > On 21/03/2023 8:04 a.m., PIKAL Petr wrote: > > Dear all. > > > > > > > > I am trying to install missing (not installed) packages during startup > > of R through code in Rprofile.site but I miserably failed and I am not > > sure what I am doing wrong. > > > > > > > > R is installed to C:Program files but it is not writable for the > > users, therefore I cannot change Rprofile.site located in root etc > > directory. I however can put Rprofile.site in users home directory > > (Documents) and use it for R startup setting (partly). > > > > However I want for less experienced users to put a code here to check > > installed packages, check if some specified set of packages is > > installed and install them, but it is not working. > > > > > > > > The code in Rprofile.site is: > > > > > > > > #** > > > > test <- scan("pack.txt", character(), quote = "") > > > > inst <- installed.packages() > > > > install.packages(test[!test %in% inst], > > repos="https://cloud.r-project.org;) > > > > #** > > > > > > > > An example of pack.txt is e.g. > > > > ggplot2 > > > > zoo > > > > > > > > but the code is not executed and packages are not installed. If I use > > this code after R starts, everything is OK and packages are installed > > to > > > > > > > >> Sys.getenv("R_LIBS_USER") > > > > [1] "C:\\Users\\PikalP\\AppData\\Local/R/win-library/4.2" > > > >> > > > > The same applies if I put e.g. library(MASS) in the Rprofile.site, the > > package is not loaded but after R is live, library(MASS) loads a package. > > > > > > > > So my question is What is the best way to check after fresh R > > installation if some predefined set of packages is installed and if > > not, perform an installation without user intervention in Windows > environment? > > > > > > > > S pozdravem | Best Regards > > > > Petr > > > > > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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 -- To UNSUBSCRIBE and more, see 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] Rprofile.site and automatic installation of missing packages
?Startup says: "Note that when the site and user profile files are sourced only the base package is loaded, so objects in other packages need to be referred to by e.g. utils::dump.frames or after explicitly loading the package concerned." So you need utils::installed.packages and utils::install.packages . Duncan Murdoch On 21/03/2023 8:04 a.m., PIKAL Petr wrote: Dear all. I am trying to install missing (not installed) packages during startup of R through code in Rprofile.site but I miserably failed and I am not sure what I am doing wrong. R is installed to C:Program files but it is not writable for the users, therefore I cannot change Rprofile.site located in root etc directory. I however can put Rprofile.site in users home directory (Documents) and use it for R startup setting (partly). However I want for less experienced users to put a code here to check installed packages, check if some specified set of packages is installed and install them, but it is not working. The code in Rprofile.site is: #** test <- scan("pack.txt", character(), quote = "") inst <- installed.packages() install.packages(test[!test %in% inst], repos="https://cloud.r-project.org;) #** An example of pack.txt is e.g. ggplot2 zoo but the code is not executed and packages are not installed. If I use this code after R starts, everything is OK and packages are installed to Sys.getenv("R_LIBS_USER") [1] "C:\\Users\\PikalP\\AppData\\Local/R/win-library/4.2" The same applies if I put e.g. library(MASS) in the Rprofile.site, the package is not loaded but after R is live, library(MASS) loads a package. So my question is What is the best way to check after fresh R installation if some predefined set of packages is installed and if not, perform an installation without user intervention in Windows environment? S pozdravem | Best Regards Petr __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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 -- To UNSUBSCRIBE and more, see 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.