cboettig / knitcitations

:package: Generate citations for knitr markdown and html files
http://carlboettiger.info
Other
220 stars 28 forks source link

error when knit-ing file from command-line #52

Closed johnstantongeddes closed 10 years ago

johnstantongeddes commented 10 years ago

Hi Carl, I'm trying to use 'knitcitations' to format Rmarkdown files that become jekyll (md) entries for my online-lab notebook - modeled on the setup that you use for your open notebook. My problem is that when I 'knit' a file containing citep() from the commandline using

Rscript -e "library(knitr); knit('knittest.Rmd')"

I get the error message

   inline R code fragments

  Error in FUN(1L[[1L]], ...) : could not find function "is"

though if I "Knit HTML" through the RStudio interface it knits perfectly.

Reproducible example:

    ---
    layout: posts
    categories: Category
    title: Test
    ---

    ```{r, echo=FALSE}
    suppressMessages(library(knitcitations))
Cite this paper `r citet("10.2307/2409084")`.

### References

```{r bib, echo=FALSE, results='asis'}
bibliography()
```


I'd be happy to hear if there's a better way to do this. My current workflow is to convert any .Rmd files in my `_posts` directory to md using the [knit](https://github.com/yihui/knitr/blob/master/inst/bin/knit) command, move these files to a 'cache' directory, and then `jekyll build`. Script [here](https://github.com/johnstantongeddes/johnstantongeddes.org/blob/master/publish.sh). There's probably a better way...
cboettig commented 10 years ago

My guess is that you need library(methods) when you run with Rscript? A bunch of packages that ship with base R aren't always loaded by Rscript and friends, even though they are loaded for interactive R. Try having you script output the results of sessionInfo() to check.

Yeah, I use a somewhat similar workflow which I'm not really satisfied with either. My site builds slowly enough as it is (no doubt due to my crappy hacks of ruby for a few simple jekyll plugins) that I don't want to be running knitr every time I build the site, so I just run that step separately when writing the post.

A more jekyll-native solution would probably use a plugin to run knitr where necessary. With posts are only using knitr / .Rmd for citations and not for other R calculations, I'm tempted to just replace them with a filter that would just find DOIs (and possibly other links) in the post and format them as citations and generate the bibliography automatically. Haven't gotten around to that.

Meanwhile, you might want to check out this new R package http://cran.r-project.org/web/packages/RefManageR/ which has some richer formatting options, etc.

johnstantongeddes commented 10 years ago

Thanks, adding library(methods) fixed it!

Though your idea about a filter for DOIs would work, I still would need a .Rmd --> .md solution as I sometimes like to embed other R code in my posts. That is, I'm not using knitr primarily for generating a bibliography. As long as I'm already using it, it's convenient to use knitcitations rather than copy-paste from Zotero which was what I've been doing. Since I only run knitr once for each .Rmd file (after knitting, I move the .Rmd file to a cache directory that is ignored by jekyll) it doesn't add much to my build time.

I'll look into RefManageR.

Thanks again for developing this!

cboettig commented 10 years ago

Ah right, you're moving it to cache automatically and you're not knitting files in cache, only in post. I missed that at first glance, that's already a better system then mine at least!

johnstantongeddes commented 10 years ago

Thanks! Happy to make meager contributions...

On Fri, Mar 7, 2014 at 2:09 PM, Carl Boettiger notifications@github.comwrote:

Ah right, you're moving it to cache automatically and you're not knitting files in cache, only in post. I missed that at first glance, that's already a better system then mine at least!

Reply to this email directly or view it on GitHubhttps://github.com/cboettig/knitcitations/issues/52#issuecomment-37056664 .

lcolladotor commented 9 years ago

Bioconductor builds and checks pacakges on several OS including Windows Server 2008 R2 Enterprise SP1 (64-bit)/x64. On that system, you have to include library(methods) on the Makefile if you are using knitcitations in the vignette. Otherwise you get an error using the current CRAN release (version 1.0.1)