Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using require() is a bad idea, and so is install.packages() #15

Open
gaborcsardi opened this issue Nov 30, 2022 · 2 comments
Open

Using require() is a bad idea, and so is install.packages() #15

gaborcsardi opened this issue Nov 30, 2022 · 2 comments

Comments

@gaborcsardi
Copy link

gaborcsardi commented Nov 30, 2022

Because they do not stop on errors, that is why they are "best performing". You are basically ignoring errors:

{ require("foobar") ; install.packages(tempfile()); message("\nNOT GOOD!!!\n") }

See how "NOT GOOD" is printed here:

Loading required package: foobar
Installing package into ‘/Users/gaborcsardi/Library/R/arm64/4.2/library’
(as ‘lib’ is unspecified)

NOT GOOD!!!

Warning messages:
1: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘foobar’
2: package ‘/var/folders/ph/fpcmzfd16rgbbk8mxvy9m2_h0000gn/T//Rtmph0Pd7A/file12c3c78c562f5’ is not available for this version of R

A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages

OTOH you could argue that if the script finishes anyway, then those packages were not really needed in the first place....

@atrisovic
Copy link
Owner

Hey @gaborcsardi,
Thanks for opening the issue!
Ok interesting! That may suggest that the actual results are worse than in my experiment. Do you have a suggestion on how the require/install.packages bit can be improved?

@gaborcsardi
Copy link
Author

You can check if the package can be loaded (with library() or loadNamespace()) after the installation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants