HenrikBengtsson / startup

:wrench: R package: startup - Friendly R Startup Configuration
https://henrikbengtsson.github.io/startup/
163 stars 5 forks source link

startup 0.14.1: Package tests trying to write to $HOME(?!?) #90

Closed HenrikBengtsson closed 4 years ago

HenrikBengtsson commented 4 years ago

Investigate the following error from https://www.r-project.org/nosvn/R.check/r-release-windows-ix86+x86_64/startup-00check.html:

Version: 0.14.1
Check: tests
Result: ERROR
     Running 'api.R' [1s]
     Running 'assert-vignettes.R' [0s]
     Running 'backup.R' [0s]
     Running 'check.R' [0s]
     Running 'current_script.R' [0s]
     Running 'debug.R' [0s]
     Running 'filter_files.R' [1s]
     Running 'find_files.R' [0s]
     Running 'install.R' [0s]
     Running 'startup.R' [1s]
     Running 'startup_session_options.R' [0s]
     Running 'sysinfo.R' [0s]
     Running 'unload.R' [0s]
    Running the tests in 'tests/api.R' failed.
    Complete output:
     > options(startup.dryrun = TRUE)
     >
     > message("*** api() ...")
     *** api() ...
     >
     > message("*** api()")
     *** api()
     > api <- startup:::api()
     > stopifnot(is.list(api), length(api) > 0)
     >
     > message("*** renviron_d()")
     *** renviron_d()
     > res <- startup::renviron_d()
     > stopifnot(all.equal(res, api))
     >
     > message("*** rprofile_d()")
     *** rprofile_d()
     > res <- startup::rprofile_d()
     Backed up R startup file: '~/.Rprofile' (0 bytes) -> '~/.Rprofile.bak.20200830-052402' (0 bytes)
     Error in file(file, ifelse(append, "a", "w")) :
     cannot open the connection
     In addition: Warning message:
     In file(file, ifelse(append, "a", "w")) :
     cannot open file 'C:\Users\CRAN\Documents/.Rprofile': Permission denied
     Error in check_rprofile_eof(all = all, fix = fix, backup = backup, debug = debug) :
     startup::check(): SYNTAX ERROR: Tried to add missing newline to the end of file ~/.Rprofile, which otherwise would cause R to silently ignore the file in the startup process, but failed.
     Calls: <Anonymous> -> check -> check_rprofile_eof
     Execution halted
    Running the tests in 'tests/check.R' failed.
    Complete output:
     > message("*** Checks ...")
     *** Checks ...
     >
     > startup::check(fix = FALSE)
     Error in check_rprofile_eof(all = all, fix = fix, backup = backup, debug = debug) :
     startup::check(): SYNTAX ERROR: File ~/.Rprofile is missing a newline at the end of the file, which most likely will cause R to silently ignore the file in the startup process.
     Calls: <Anonymous> -> check_rprofile_eof
     Execution halted
    Running the tests in 'tests/startup.R' failed.
    Complete output:
     > renviron_d <- startup::renviron_d
     > rprofile_d <- startup::rprofile_d
     >
     > message("*** startup() ...")
     *** startup() ...
     >
     > message("*** renviron_d() ...")
     *** renviron_d() ...
     >
     > paths <- system.file("Renviron.d", package = "startup")
     > print(paths)
     [1] "D:/temp/RtmpugIzM2/RLIBS_20a2872a537e9/startup/Renviron.d"
     > api <- renviron_d(paths = paths, skip = FALSE)
     > str(api)
     List of 3
     $ renviron_d:function (sibling = FALSE, all = FALSE, unload = FALSE, skip = NA, dryrun = NA,
     debug = NA, paths = NULL)
     $ rprofile_d:function (sibling = FALSE, all = FALSE, check = NA, unload = FALSE, skip = NA,
     on_error = c("error", "warning", "immediate.warning", "message", "ignore"),
     dryrun = NA, debug = NA, paths = NULL)
     $ unload :function (debug = FALSE)
     > renviron_d(paths = paths, skip = FALSE, dryrun = TRUE)
     >
     > message("*** renviron_d() ... DONE")
     *** renviron_d() ... DONE
     >
     > message("*** rprofile_d() ...")
     *** rprofile_d() ...
     >
     > paths <- system.file("Rprofile.d", package = "startup")
     > print(paths)
     [1] "D:/temp/RtmpugIzM2/RLIBS_20a2872a537e9/startup/Rprofile.d"
     > api <- rprofile_d(paths = paths, skip = FALSE)
     Backed up R startup file: '~/.Rprofile' (0 bytes) -> '~/.Rprofile.bak.20200830-052406' (0 bytes)
     Error in file(file, ifelse(append, "a", "w")) :
     cannot open the connection
     In addition: Warning message:
     In file(file, ifelse(append, "a", "w")) :
     cannot open file 'C:\Users\CRAN\Documents/.Rprofile': Permission denied
     Error in check_rprofile_eof(all = all, fix = fix, backup = backup, debug = debug) :
     startup::check(): SYNTAX ERROR: Tried to add missing newline to the end of file ~/.Rprofile, which otherwise would cause R to silently ignore the file in the startup process, but failed.
     Calls: rprofile_d -> check -> check_rprofile_eof
     Execution halted
Flavor: r-release-windows-ix86+x86_64
HenrikBengtsson commented 4 years ago

Lots of tests end up trying to fix ~/.Rprofile if it does not have a newline at the end, e.g. with

$ printf "#" > ~/.Rprofile
$ chmod ugo-w ~/.Rprofile

we get:

── Test failures ────────────────────────────────────────────────────── api ────

> options(startup.dryrun = TRUE)
> 
> message("*** api() ...")
*** api() ...
> 
> message("*** api()")
*** api()
> api <- startup:::api()
> stopifnot(is.list(api), length(api) > 0)
> 
> message("*** renviron_d()")
*** renviron_d()
> res <- startup::renviron_d()
> stopifnot(all.equal(res, api))
> 
> message("*** rprofile_d()")
*** rprofile_d()
> res <- startup::rprofile_d()
Backed up R startup file: '~/.Rprofile' (1 bytes) -> '~/.Rprofile.bak.20200902-194354' (1 bytes)
Error in file(file, ifelse(append, "a", "w")) : 
  cannot open the connection
In addition: Warning message:
In file(file, ifelse(append, "a", "w")) :
  cannot open file '/home/hb/.Rprofile': Permission denied
Error in check_rprofile_eof(all = all, fix = fix, backup = backup, debug = debug) : 
  startup::check(): SYNTAX ERROR: Tried to add missing newline to the end of file ~/.Rprofile, which otherwise would cause R to silently ignore the file in the startup process, but failed.
Calls: <Anonymous> -> check -> check_rprofile_eof
Execution halted

── Test failures ──────────────────────────────────────────────────── check ────

> message("*** Checks ...")
*** Checks ...
> 
> startup::check(fix = FALSE)
Error in check_rprofile_eof(all = all, fix = fix, backup = backup, debug = debug) : 
  startup::check(): SYNTAX ERROR: File ~/.Rprofile is missing a newline at the end of the file, which most likely will cause R to silently ignore the file in the startup process.
Calls: <Anonymous> -> check_rprofile_eof
Execution halted

── Test failures ────────────────────────────────────────────────── startup ────

> renviron_d <- startup::renviron_d
> rprofile_d <- startup::rprofile_d
> 
> message("*** startup() ...")
*** startup() ...
> 
> message("*** renviron_d() ...")
*** renviron_d() ...
> 
> paths <- system.file("Renviron.d", package = "startup")
> print(paths)
[1] "/tmp/hb/RtmpNPHwHS/file25046dcf3af6/startup.Rcheck/startup/Renviron.d"
> api <- renviron_d(paths = paths, skip = FALSE)
> str(api)
List of 3
 $ renviron_d:function (sibling = FALSE, all = FALSE, unload = FALSE, skip = NA, dryrun = NA, 
    debug = NA, paths = NULL)  
 $ rprofile_d:function (sibling = FALSE, all = FALSE, check = NA, unload = FALSE, skip = NA, 
    on_error = c("error", "warning", "immediate.warning", "message", "ignore"), 
    dryrun = NA, debug = NA, paths = NULL)  
 $ unload    :function (debug = FALSE)  
> renviron_d(paths = paths, skip = FALSE, dryrun = TRUE)
> 
> message("*** renviron_d() ... DONE")
*** renviron_d() ... DONE
> 
> message("*** rprofile_d() ...")
*** rprofile_d() ...
> 
> paths <- system.file("Rprofile.d", package = "startup")
> print(paths)
[1] "/tmp/hb/RtmpNPHwHS/file25046dcf3af6/startup.Rcheck/startup/Rprofile.d"
> api <- rprofile_d(paths = paths, skip = FALSE)
Backed up R startup file: '~/.Rprofile' (1 bytes) -> '~/.Rprofile.bak.20200902-194355' (1 bytes)
Error in file(file, ifelse(append, "a", "w")) : 
  cannot open the connection
In addition: Warning message:
In file(file, ifelse(append, "a", "w")) :
  cannot open file '/home/hb/.Rprofile': Permission denied
Error in check_rprofile_eof(all = all, fix = fix, backup = backup, debug = debug) : 
  startup::check(): SYNTAX ERROR: Tried to add missing newline to the end of file ~/.Rprofile, which otherwise would cause R to silently ignore the file in the startup process, but failed.
Calls: rprofile_d -> check -> check_rprofile_eof
Execution halted

Two types of problems occur:

  1. tests/check.R checks user's ~/.Rprofile file and if that is invalid, it throws an error => test is depending on user's check environment
  2. tests/{api,startup}.R attempts to fix user's ~/.Rprofile file and if that is not possible, it throws an error => test is depending on user's check environment. Also, this is more serious because it actually attempts to edit that file.