Closed fmichonneau closed 9 years ago
I also think it's poor form to install packages in .Rmd
or .R
files that you're suggesting someone else run. Personally, I manage/track what I've installed and don't like to install packages willy-nilly like this. I like the approach where you check if it's there, stop if not, and provide the code to install, for the person to run if/as they wish.
I agree. Do you think I should update the language to make these ideas more explicit?
No, don't think it's the time or place for that. I just always point this out when people include install.packages()
in these sorts of contexts. A pet peeve.
So is the preferred approach then something like:
if(!require(foo)) {
stop("Please install 'foo' with install.packages('foo')")
}
Is that any better than
library(foo)
which already throws an error if foo is not found:
Error in library(foo) : there is no package called ‘foo’
I guess it depends if you need to have the function in there for beginners on how to install packages? Or is it better to just assume people can figure that out on their own?
Well in general R cannot assume that install.packages()
will work -- a
different package repo than cran may be required, or perhaps
install_github
, etc. If you want to distribute a script that knows how
to automatically install its dependencies, it would be much more reliable
to do so as an R package, with this information in the DESCRIPTION file.
Otherwise, probably best to just stick with "library()".
Just my 2c, apologies if this is a particularly pedantic position.
On Mon, Jun 1, 2015 at 3:45 PM Naupaka Zimmerman notifications@github.com wrote:
I guess it depends if you need to have the function in there for beginners on how to install packages? Or is it better to just assume people can figure that out on their own?
— Reply to this email directly or view it on GitHub https://github.com/Reproducible-Science-Curriculum/rr-intro/pull/9#issuecomment-107739246 .
I think the problem with "giving nicer error messages for beginners" is despite the good intentions, everyone predicts a different subset of bad error messages to alter, and the resulting error messages are inconsistent and un-googleable.
I tend to favour simplicity here.
On 08:45, Tue, 02/06/2015 Naupaka Zimmerman notifications@github.com wrote:
I guess it depends if you need to have the function in there for beginners on how to install packages? Or is it better to just assume people can figure that out on their own?
— Reply to this email directly or view it on GitHub https://github.com/Reproducible-Science-Curriculum/rr-intro/pull/9#issuecomment-107739246 .
I'm not sure what the cleanest solution is though I agree that the implementation that was originally in this Rmd file was problematic, especially because it didn't work for some Windows users at the Duke workshop.
I like nicer error messages, but I agree that un-googleability is a concern.
I use the approach of starting with an Rmd file that "magically" works in my teaching, but that works well when the students are accessing RStudio via the server where all packages they need initially are pre-installed. This is not the case for the workshop.
Perhaps an all inclusive Rmd file is not a great solution here, and we just need to start with "install these packages" at the beginning and then have them knit the Rmd file?
:+1: for starting with explicit "installation instructions"
Also :+1: for explicit install instructions. It is also showing them how to install other packages later.
Additionally using the require function is better to check that the package exists locally.