Skip to content


Subversion checkout URL

You can clone with
Download ZIP


knitr vs knit2html rstudio button #14

rmflight opened this Issue · 9 comments

3 participants


Hi Carl,

I have been looking at the problem of getting differences between using the rstudio knit2html button and calling knitr directly, and there is something very weird going on. The options()$work_citations does not change in one case, but does in the other. BUT, the first instance of modifying work_citations works.

When using knit2html button (, the work_citations option does not get updated. I even tried putting this in a for loop to make sure that it wasn't due to being in the sapply, and it still doesnt update.

However, when I call knitr from the command line, the work_citations option does get updated properly. I've been trying to figure this out all morning, and not having any luck. I am going to submit this as an issue to yihui and rstudio as well, because this seems odd.

I put up the example with both outputs here:

@rmflight rmflight referenced this issue in yihui/knitr

knitr vs knit2html rstudio button #407


I've tried to recreate this behavior independently by creating a package that basically only modifies one option variable, with no luck. You can see my effort here:


So do you know why this happens? I'm curious why it should be happening in knitcitations and not when I write a package that tries to do the same basic manipulation of the option space.

I had also tried using "global" variables to store stuff, and didn't have any luck with that either.


Hmm, just discovered that knitr will let you make assignments in an inline statement. So I could imagine doing something like having a function that updates a bibliographic object, and as a side effect prints the inline citation


No, I'm saying you could use an assignment inline to update the object, then you don't have to worry about creating your own environment (although that does sound like an interesting idea).


r I(inObj <- insertStoreText(inObj, "hello world"))

Here insertStoreText prints the "hello world" as a side effect, while updating inObj at the same time (see as a trivial example of this).

I never thought of this before because all of yihui's inline examples are just printing previously saved objects, but it turns out there is no problem with putting in full assignments as well. This way the bibliography object is guaranteed to be local, and updated, and provides a lot of flexibility for the user, and for you, because all of your functions then require the user to pass in the object that has the stored info for the final bibliography.


Well, I tried using an environment, and I still get the same differences I did when we were using options. Could you try it and see if it does the same thing for you Carl? I have a branch based more or less on your original code that now uses environments.

What is really weird about this is it inserts the first reference, and then refuses to insert any following references.

You can see the differences in, and, which are knit2html button and knitr, respectively.

I know its accessing the environment at least once.


I looked at this problem for a while, and could not understand it either...

@cboettig cboettig closed this issue from a commit
@cboettig Semantic citations enabled; plus minor improvements. v0.3-2
* Semantic citations now enabled.  `bibliography` can print with method 'rdfa'
  to provide RDFa enhanced HTML bibliography data, and citations can take cito
  arguments as an option. (Closes issues #16 and #17)
* `bibliography` now takes more options to match the `bibstyle` and `print.bibentry`
* `citet` and `citep` take an optional argument for formating the citation, defaulting
  to `authoryear` format.  Future versions may move this into an option.
* `newbib()` function initializes and clears existing cache files.
* updated with semantic examples and more background text (generated by
* Some basic unit tests built in.  Could use more, but meanwhile closes #8.
* Test cases work with knit2html button in RStudio, closes #14
@cboettig cboettig closed this in b747226
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.