user2694363
user2694363

Reputation: 13

knitr updated from 1.2 to 1.4 error: Quitting from lines

I recently updated knitr to 1.4, and since then my .Rnw files don't compile. The document is rich (7 chapters, included with child=""). Now, in the recent knitr version I get an error message:

    Quitting from lines 131-792 (/DATEN/anna/tex/CoSta/chapter1.Rnw) 
    Quitting from lines 817-826 (/DATEN/anna/tex/CoSta/chapter1.Rnw) 
    Fehler in if (eval) { : 
    Argument kann nicht als logischer Wert interpretiert werden

(the last two lines mean that knitr is looking for a logical and it cannot find it. At those lines 131 and 817 two figures end. Compiling these sniplets separately will work. I have no idea how to resolve this problem. Thank's in advance for any hints that allow to resolve my issue.

Here is the sessionInfo()

    R version 2.15.1 (2012-06-22)
    Platform: x86_64-pc-linux-gnu (64-bit)

    locale:
      [1] LC_CTYPE=de_DE.UTF-8       LC_NUMERIC=C              
      [3] LC_TIME=de_DE.UTF-8        LC_COLLATE=de_DE.UTF-8    
      [5] LC_MONETARY=de_DE.UTF-8    LC_MESSAGES=de_DE.UTF-8   
      [7] LC_PAPER=C                 LC_NAME=C                 
      [9] LC_ADDRESS=C               LC_TELEPHONE=C            
      [11] LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C       

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

      other attached packages:
      [1] knitr_1.4

      loaded via a namespace (and not attached):
      [1] compiler_2.15.1 digest_0.6.3    evaluate_0.4.7  formatR_0.9    
      [5] stringr_0.6.2   tcltk_2.15.1   

Following the suggestions of Hui, I run each chapter separately with knit("chapter1.Rnw") and so on. No error message occurs, and separate tex files are created. To provide more information I display part of the code. There is a main document in which several options are set

     <<options-setting,echo=FALSE>>=
     showthis <- FALSE
     evalthis <- FALSE
     evalchapter <- TRUE
     opts_chunk$set(comment=NA, fig.width=6, fig.height=4)
     @

The each chapter is used via child chunks, e.g. chapter1 is called from

     <<child-chapter1, child='chapter1.Rnw', eval=evalchapter>>=
     @

The error message which appears when knitting the main Rnw file was given above. The related Figure environment is as follows

     \begin{figure}[ht]
       \centering
      <<wuerfel-simulation,echo=showthis,fig.height=5>>=
      data.sample6 <- sample(1:6,repl=TRUE,100)
      table(data.sample6)
      barplot(table(data.sample6)/100,col=5,main="Haeufigkeiten beim Wuerfeln")
      @ 
      \caption{Visualisierung beim W"urfeln. 100 Versuche.}
      \label{fig:muent-vis}
      \end{figure}

This is not very advanced, but the error is still as it was given before. The quitting from lines concerns a long text, from 131 (end of first chunk) to line 792 (beginning of the followup chunk), which is

       << zeiten, echo=showthis,eval=evalthis>>=
       zeiten <- c(17,16,20,24,22,15,21,15,17,22)
       max(zeiten)
       mean(zeiten)
       zeiten[4] <- 18; zeiten
       mean(zeiten)
       sum(zeiten > 20)
       @

Is there a problem with correctly closing a chunk?

I now located the error and I provide a short piece of code with reproducible error message.It concerns conditional evaluation of child processes involving Sexpr:

The main file is the following

    \documentclass{article}
    \begin{document}
    <<options-setting,echo=FALSE>>=
    evalchapter <- TRUE
    @
    <<test,child="test-child.Rnw", eval=evalchapter>>=
    @ 
    \end{document}

The related child file 'test-child.Rnw' is

     <<no-sexpr>>=
     t <- 2:4
     @ 
     text \Sexpr{(t <- 2:4)}

knitting this 'as is' gives the error message from above. Removing the Sexpr in the child everything works nicely. But, everything also works nicely, if I remove the conditioning in the call of the child file, i.e., without 'eval=evalchapter'

Since I use Sexpr quite often I would like to have a solution to this problem. As I mentioned earlier, there were no problems up to knitR Version 1.2.

Upvotes: 1

Views: 4767

Answers (1)

Yihui Xie
Yihui Xie

Reputation: 30174

This is related to a change in knitr 1.3 and mentioned in the NEWS:

added an argument options to knit_child() to set global chunk options for child documents; if a parent chunk calls a child document (via the child option), the chunk options of the parent chunk will be used as global options for the child document, e.g. for <<foo, child='bar.Rnw', fig.path='figure/foo-'>>=, the figure path prefix will be figure/foo- in bar.Rnw; see How to avoid figure filenames in child calls for an application

And this caused a bug for inline R code. In your case, the chunk option eval=evalchapter was not evaluated when it is used for evaluating inline code. I have fixed the bug in the development version v1.4.5 on Github.

Upvotes: 1

Related Questions