Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

options() not respected in child documents #306

Closed
cmmp opened this issue Jul 5, 2012 · 3 comments
Closed

options() not respected in child documents #306

cmmp opened this issue Jul 5, 2012 · 3 comments
Labels
bug Bugs
Milestone

Comments

@cmmp
Copy link
Contributor

cmmp commented Jul 5, 2012

I'm trying to control the number of digits for inline tex output. While this works if the options(digits = x) is set in the same document as the code, if it's set on the parent it is ignored.

Here's a simple example:

sample.Rnw:

\documentclass[a4paper]{article}

\begin{document}

<<setup>>=
options(digits = 2)
@ 

\title{Test}

\section{Test}
Calling child:
\Sexpr{knit_child('child.Rnw')}


\end{document}

child.Rnw:

<<>>=
x = 1.2109382103921
@

Just a test, $x = \Sexpr{x}$.

Makefile:

all:
        R -e "require(knitr); knit('sample.Rnw')"
        pdflatex sample.tex

output of child.tex:

\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
x = 1.2109382103921
\end{alltt}
\end{kframe}
\end{knitrout}


Just a test, $x = 1.2109$.

if options(digits=2) is set on child.Rnw, then the output is correct:

correct-child.tex:

\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
x = 1.2109382103921
\hlfunctioncall{options}(digits = 2)
\end{alltt}
\end{kframe}
\end{knitrout}


Just a test, $x = 1.21$.

relevant info:

> require(knitr)
Loading required package: knitr
> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-unknown-linux-gnu (64-bit)

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

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

other attached packages:
[1] knitr_0.6.8

loaded via a namespace (and not attached):
[1] digest_0.5.2   evaluate_0.4.2 formatR_0.5    plyr_1.7.1     stringr_0.6   
[6] tools_2.15.1  

Expected behavior: I believe that if an option is set at the parent document, I shouldn't have to repeat it at every child... following DRY.

Thanks for the hard work on this package!

@yihui
Copy link
Owner

yihui commented Jul 5, 2012

That is easy to fix; will do it this evening. Thanks for the detailed report!

@yihui
Copy link
Owner

yihui commented Jul 5, 2012

The fix for this issue is to move lines 176-182 before line 117 in https://github.com/yihui/knitr/blob/master/R/output.R#L117

cmmp added a commit to cmmp/knitr that referenced this issue Jul 5, 2012
@yihui yihui closed this as completed in 0b80d32 Jul 5, 2012
yihui added a commit that referenced this issue Jul 7, 2012
@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bugs
Projects
None yet
Development

No branches or pull requests

2 participants