datacarpentry / rr-intro

Introduction materials for Reproducible Research Curriculum
http://www.datacarpentry.org/rr-intro/
Other
10 stars 18 forks source link

can't install packages within knitr document #9

Closed fmichonneau closed 9 years ago

fmichonneau commented 9 years ago

Additionally using the require function is better to check that the package exists locally.

jennybc commented 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.

fmichonneau commented 9 years ago

I agree. Do you think I should update the language to make these ideas more explicit?

jennybc commented 9 years ago

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.

naupaka commented 9 years ago

So is the preferred approach then something like:

if(!require(foo)) {
  stop("Please install 'foo' with install.packages('foo')")
}
richfitz commented 9 years ago

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’
naupaka commented 9 years ago

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?

cboettig commented 9 years ago

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 .

richfitz commented 9 years ago

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 .

mine-cetinkaya-rundel commented 9 years ago

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?

richfitz commented 9 years ago

:+1: for starting with explicit "installation instructions"

tracykteal commented 9 years ago

Also :+1: for explicit install instructions. It is also showing them how to install other packages later.