Search code examples
rwindowsstartup

R Startup on Windows10- "The system cannot find the path specified." message. How can I find the path?


This is not a big deal; everything seems to be working, but I'm bothered by a message that I receive every time I start R on Windows 10:

C:\devl\temp>R
**The system cannot find the path specified.**

R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

I've reinstalled it, changed paths in Rprofile.site, messed with my path. I can directly run the R executable:

C:\R\R-3.6.1\bin>.\x64\R.exe
The system cannot find the path specified.

and still get the message.

Anyways, I just want to understand R's startup sequence a bit better, so I'd appreciate any advice on where to look to find that path R is trying to open at startup.

Update @Pepv's link led me to the startup package's startup(debug=TRUE) function. After doing a bit of cleanup, below is the full output. The answer has to be staring me in the face now.

C:\Users>R
The system cannot find the path specified.

R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

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.

[1] "I'm the Rprofile.site in the R installation directory!"
[1] "I am the .Rprofile in C:/devl"
> startup::startup(debug = TRUE)
0.001s: System information:
0.007s: - R_HOME: 'C:/R/R-3.6.1' (existing folder)
0.012s: - R call: C:\R\R-3.6.1/bin/x64/Rterm.exe
0.017s: - Current directory: 'C:/Users'
0.022s: - User's home directory: '~' => 'C:\devl' (existing folder)
0.028s: - Search path: '.GlobalEnv', 'package:stats', 'package:graphics', 'package:grDevices', 'package:utils', 'package:datasets', 'package:methods', 'Autoloads', 'package:base'
0.044s: - Loaded namespaces: 'compiler', 'startup', 'graphics', 'utils', 'grDevices', 'stats', 'datasets', 'methods', 'base'
0.055s: The following has already been processed by R:
0.061s: - R_ENVIRON: ''
0.063s: - R_ENVIRON_USER: ''
0.068s: - R_DEFAULT_PACKAGES: '' (= 'base,methods,datasets,utils,grDevices,graphics,stats')
0.078s: - R_LIBS: 'C:\devl\Rpackages'
0.083s: - R_LIBS_SITE: ''
0.086s: - R_LIBS_USER: 'C:\devl\Rpackages'
0.090s: - R_PROFILE: ''
0.095s: - R_PROFILE_USER: 'C:\devl\.Rprofile' (1 lines; 42 bytes)
0.105s: - 'C:/R/R-3.6.1/etc/Rprofile.site' (2 code lines; 619 bytes)
0.117s: - 'C:\devl\.Rprofile' (1 code lines; 42 bytes)
0.124s: startup::startup()-specific processing ...
0.130s: Found startup directory '~/.Renviron.d'.
0.145s: Processing 1 Renviron files ...
0.153s:  - 'C:\devl/.Renviron.d/.Renviron' (0 lines; 0 bytes) setting 0 environment variables
0.164s: Processing 1 Renviron files ... done
0.177s: Found startup directory 'C:\devl\.Rprofile.d'.
0.188s: Processing 1 Rprofile files ...
0.196s:  - 'C:\devl\.Rprofile.d/.Rprofile' (1 code lines; 30 bytes)
[1] "I am in .Rprofile.d"
0.208s: Processing 1 Rprofile files ... done
0.216s: - unloading the 'startup' package
0.222s: - Search path: '.GlobalEnv', 'package:stats', 'package:graphics', 'package:grDevices', 'package:utils', 'package:datasets', 'package:methods', 'Autoloads', 'package:base'
0.238s: - Loaded namespaces: 'compiler', 'graphics', 'utils', 'grDevices', 'stats', 'datasets', 'methods', 'base'
0.250s: startup::startup()-specific processing ... done
0.257s: The following will be processed next by R:
0.262s: - R_HISTFILE: ''
0.274s: - .First(): no such function on search()
0.279s: - Remaining packages per R_DEFAULT_PACKAGES to be attached by base::.First.sys() (in order):

Update 2 Or maybe not. Rterm.exe does not trigger the message, and per this source, "R (as opposed to Rterm) is a small .exe program that does a little argument parsing, then runs Rterm." Even R.exe --help triggers the message so this must have something to do with the actual R.exe argument parsing. Close to closing this question.


Solution

  • When R starts, the following user-specific setup takes place:

    The first .Renviron file found on the R startup search path is processed. The search path is (in order): (i) Sys.getenv("R_ENVIRON_USER"), (ii) ./.Renviron, and (iii) ~/.Renviron. The format of this file is one ENV_VAR=VALUE statement per line, cf. ?.Renviron. NOTE: Some environment variables must be set already in this step in order to be acknowledged by R, i.e. it is too late to set some of them in Step 2 and Step 3 below.

    The first .Rprofile file found on the R startup search path is processed. The search path is (in order): (i) Sys.getenv("R_PROFILE_USER"), (ii) ./.Rprofile, and (iii) ~/.Rprofile. The format of this file must be a valid R script (with a trailing newline), cf. ?.Rprofile.

    If the .Rprofile file (in Step 2) calls startup::startup() then the following will also take place:

    a. The first .Renviron.d directory on the R startup search path is processed. The search path is (in order): (i) paste0(Sys.getenv("R_ENVIRON_USER"), ".d"), (ii) ./.Renviron.d, and (iii) ~/.Renviron.d. The format of these files should be the same as for .Renviron. NOTE: Some environment variables must be set already in Step 1 above in order to be acknowledged by R.

    b. A set of handy R options that can be use in Step 3c are set. Their names are prefixed startup.session. - see ?startup::startup_session_options for details.

    c. The first .Rprofile.d directory found on the R startup search path is processed. The search path is (in order): (i) paste0(Sys.getenv("R_PROFILE_USER"), ".d"), (ii) ./.Rprofile.d, and (iii) ~/.Rprofile.d. The format of these files should be the same as for .Rprofile, that is, they must be valid R scripts.

    d. If no errors occur above, the startup package will be unloaded, leaving no trace of itself behind, except for R options startup.session.* set in Step 3b - these will be erased if startup::startup() is called with keep = NULL.

    Info extracted from https://cran.r-project.org/web/packages/startup/vignettes/startup-intro.html

    EDIT:

    Check this solution, maybe it also works for you: Problems executing script from command line in R. Error message: cannot find path specified