RevolutionAnalytics / checkpoint

Install R packages from snapshots on checkpoint-server
164 stars 38 forks source link

knitr isn't installed in ~/.checkpoint #169

Closed chatchavan closed 9 years ago

chatchavan commented 9 years ago

I use checkpoint() in my R Markdown (.Rmd) file to create a script for other experimenters to reproduce the analysis. However, knitr wasn't installed in the snapshot folder (under ~/.checkpoint). As a result, the .Rmd file wasn't parsed for required libraries and fails to run.

It seems that knitr is loaded, but not installed (see the console output below). There's no knitr in ~/.checkpoint/2015-02-12/lib/x86_64-apple-darwin13.4.0/3.1.2/.

Quick fix: Manually install knitr within the checkpoint environment allows checkpoint to work correctly.

Why it's still a problem: Although this solves problem in my computer, I'd expect anybody who use my script to reproduce the analysis to be able to knit the .Rmd without messing in the console.

> checkpoint("2015-02-12", R.version = "3.1.2", use.knitr = TRUE)
* installing *binary* package ‘compiler’ ...
* DONE (compiler)
Scanning for packages used in this project
Loading required package: knitr
  |==========================================================================================================| 100%
- Discovered 4 packages
Installing packages used in this project 
 - Installing ‘assertthat’
 - Installing ‘foreach’
also installing the dependencies ‘codetools’, ‘iterators’

 - Installing ‘sqldf’
also installing the dependencies ‘gsubfn’, ‘proto’, ‘RSQLite’, ‘DBI’, ‘chron’

 - Installing ‘testthat’
also installing the dependency ‘digest’

checkpoint process complete

---
Warning messages:
1: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
  there is no package called ‘knitr’
2: In projectScanPackages(project, use.knitr = use.knitr) :
  The knitr package is not available and Rmarkdown files will not be parsed

> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] checkpoint_0.3.7

loaded via a namespace (and not attached):
[1] tools_3.1.2
andrie commented 9 years ago

Did you have a call to

library("knitr")

in your checkpoint project?

We don't treat knitr different from any other package. If checkpoint() finds knitr, it will install it.

chatchavan commented 9 years ago

Yes, I have that line in the source code.

The problem was that checkpoint skipped parsing the .Rmd file in the first place. Therefore, any library listed in that file aren't installed.

andrie commented 9 years ago

I'm not sure I understand. In principle, your library(knitr) should be discovered and installed if you have this statement in any .R file.

To build a knitr file from code, this has to be in a .R script, IIUC.

Can you share a link to your project, so I can understand better what's happening?

chatchavan commented 9 years ago

You can find a minimal project that produces error here: https://www.dropbox.com/sh/3ucvdjlefbkk6zd/AABemV-LTsOtw8x7PBemObDBa?dl=0

Further development: I found that the problem happens only when I use RStudio GUI to compile the markdown. It gives the following error in R Markdown output:

  |................................                                 |  50%
  ordinary text without R code

  |.................................................................| 100%
label: unnamed-chunk-1

processing file: source.Rmd

Quitting from lines 7-10 (source.Rmd) 
Error in library(knitr) : there is no package called 'knitr'
Calls: <Anonymous> ... withCallingHandlers -> withVisible -> eval -> eval -> library
Execution halted

However, with the same project, if I compile it with the following commands, checkpoint install knitr and parse the .Rmd files correctly.

library(knitr)
library(markdown)
knit('source.Rmd', 'output.md')
andrie commented 9 years ago

@chatchavan, thank you for this additional information.

As far as I can tell, this is documented and expected behaviour.

To knit a file, you need to have library(knitr) at the top of your script. So, when you include this, checkpoint() works correctly, as you demonstrate.

Can we close this issue? If not, can you please provide some additional information about the use case you have in mind?

chatchavan commented 9 years ago

Could you point me to where this documentation is? Before I opened this issue, I searched about the problem, but couldn't find it in either the generated R doc, README.md, or http://projects.revolutionanalytics.com/rrt/.

Afterwards, you may close this issue.

andrie commented 9 years ago

The purpose of checkpoint() is to install only the packages it discovers by searching for library(), require(), package::foo() and package:::foo().

In this case, your scripts is dependent on knitr, so when you call library(knitr) in any R script in your project, checkpoint() finds and installs it.

I'm open for any suggestions on how the documentation can be improved. Can you please make a suggestion on what exactly you want us to add? Pull requests are welcome!

piccolbo commented 9 years ago

@andrie does checkpoint parse Rmds? Sorry I forgot if we dropped that feature at some point. I think if it does, it makes sense to add knitr to the list of packages to be installed, whether it's explicitly loaded or not, whnever an Rmd is present in a project. I see it as a way of rounding out Rmd support. What's the point of parsing Rmds, if there's no way of compiling them? Whether it is in a script (which we support) or from RStudio (which we don't), an Rmd requires knitr to be of any use. As far as the docs, I think once you start to document what a package doesn't do, it's a slippery slope. If it's not documented, assume it's not available.

andrie commented 9 years ago

@piccolbo Good suggestions, thank you.

To answer your question: checkpoint parses .Rmd files if knitr is installed.

I think it does in fact make sense to add knitr and rmarkdown automatically into the repository if we encounter .Rmd files. I'll open a new issue to capture this.