X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Fexamples%2Fsweave.lyx;h=e11bcf9fef2771b9ad40ee4f70bd7358c508032e;hb=3fd0cc27d47d79513487e56a254c90e1794b6b0e;hp=51770078354aa049525ec0ca006e67f55db6a067;hpb=5e1d11d1df9de2580246b735bab2cde89456280f;p=lyx.git diff --git a/lib/examples/sweave.lyx b/lib/examples/sweave.lyx index 5177007835..e11bcf9fef 100644 --- a/lib/examples/sweave.lyx +++ b/lib/examples/sweave.lyx @@ -1,5 +1,5 @@ -#LyX 2.2 created this file. For more info see http://www.lyx.org/ -\lyxformat 504 +#LyX 2.3 created this file. For more info see http://www.lyx.org/ +\lyxformat 544 \begin_document \begin_header \save_transient_properties true @@ -36,6 +36,8 @@ sweave \font_osf false \font_sf_scale 100 100 \font_tt_scale 100 100 +\use_microtype false +\use_dash_ligatures false \graphics default \default_output_format default \output_sync 0 @@ -48,23 +50,24 @@ sweave \use_geometry true \use_package amsmath 1 \use_package amssymb 1 -\use_package cancel 0 +\use_package cancel 1 \use_package esint 1 \use_package mathdots 1 -\use_package mathtools 0 +\use_package mathtools 1 \use_package mhchem 1 -\use_package stackrel 0 -\use_package stmaryrd 0 -\use_package undertilde 0 +\use_package stackrel 1 +\use_package stmaryrd 1 +\use_package undertilde 1 \cite_engine basic \cite_engine_type default \biblio_style plain \use_bibtopic false \use_indices false \paperorientation portrait -\suppress_date false +\suppress_date true \justification true \use_refstyle 0 +\use_minted 0 \index Index \shortcut idx \color #008000 @@ -77,7 +80,10 @@ sweave \tocdepth 3 \paragraph_separation indent \paragraph_indentation default -\quotes_language english +\is_math_indent 0 +\math_numbering_side default +\quotes_style english +\dynamic_quotes 0 \papercolumns 1 \papersides 1 \paperpagestyle default @@ -91,14 +97,21 @@ sweave \begin_body \begin_layout Standard -\begin_inset ERT +\begin_inset Note Note status open \begin_layout Plain Layout +\begin_inset Flex Sweave Options +status open + +\begin_layout Plain Layout + +prefix=TRUE,prefix.string=sweave-prefix,keep.source=FALSE +\end_layout + +\end_inset + -% -\backslash -SweaveOpts{prefix=TRUE,prefix.string=sweave-prefix,keep.source=FALSE} \end_layout \end_inset @@ -149,6 +162,7 @@ LatexCommand href name "xie@yihui.name" target "xie@yihui.name" type "mailto:" +literal "false" \end_inset @@ -241,6 +255,21 @@ https://github.com/downloads/yihui/lyx/sweave.pdf . \end_layout +\begin_layout Standard +Since \SpecialChar LyX + 2.3, it is necessary to enable the use of +\emph on +needauth +\emph default + converters in +\family sans + Preferences\SpecialChar menuseparator +File Handling\SpecialChar menuseparator +Converters +\family default + in order to compile with Sweave. +\end_layout + \begin_layout Section System Requirements \end_layout @@ -306,22 +335,27 @@ bin \end_layout \begin_layout Standard -\begin_inset ERT +\begin_inset Flex Chunk status open \begin_layout Plain Layout -<>= -\end_layout +\begin_inset Argument 1 +status open \begin_layout Plain Layout -R.home('bin') +where-is-R-bin,eval=FALSE +\end_layout + +\end_inset + + \end_layout \begin_layout Plain Layout -@ +R.home('bin') \end_layout \end_inset @@ -361,22 +395,27 @@ Sweave.sty \end_layout \begin_layout Standard -\begin_inset ERT +\begin_inset Flex Chunk status open \begin_layout Plain Layout -<>= -\end_layout +\begin_inset Argument 1 +status open \begin_layout Plain Layout -file.path(R.home('share'), 'texmf', 'tex', 'latex') +sweave-sty,eval=FALSE +\end_layout + +\end_inset + + \end_layout \begin_layout Plain Layout -@ +file.path(R.home('share'), 'texmf', 'tex', 'latex') \end_layout \end_inset @@ -455,15 +494,35 @@ echo=FALSE \begin_layout Standard To write R code in \SpecialChar LyX -, you can first switch to the +, you can first insert +\family typewriter +Chunk +\family default + insets from +\family sans +Insert\SpecialChar menuseparator +Custom Insets\SpecialChar menuseparator +Chunk +\family default +, or you can simply open a \SpecialChar TeX + code environment and write Sweave code chunks + in it. + However, \SpecialChar LyX + provides a summary of all the \family typewriter Chunk \family default - environment in the layout styles list (droplist in the top-left corner - in the toolbar), or you can simply open a \SpecialChar TeX - code environment and write Sweave - code chunks in it. - The latter approach is recommended since it is more stable. + insets in the document in the +\family sans +Navigate\SpecialChar menuseparator +Literate Programming +\family default + and +\family sans +View\SpecialChar menuseparator +Outline Pane +\family default + menus. \end_layout \begin_layout Standard @@ -483,12 +542,22 @@ useFancyQuotes \end_layout \begin_layout Standard -\begin_inset ERT +\begin_inset Flex Chunk status open \begin_layout Plain Layout -<>= +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout + +setup, keep.source=TRUE +\end_layout + +\end_inset + + \end_layout \begin_layout Plain Layout @@ -501,29 +570,38 @@ status open options(width = 70, useFancyQuotes = FALSE, digits = 4) \end_layout -\begin_layout Plain Layout +\end_inset + -@ \end_layout +\begin_layout Standard +\begin_inset Flex Chunk +status open + \begin_layout Plain Layout -<>= -\end_layout +\begin_inset Argument 1 +status open \begin_layout Plain Layout -## view the Sweave vignette (requires R >= 2.13.0) +sweave-manual, eval=FALSE, keep.source=TRUE +\end_layout + +\end_inset + + \end_layout \begin_layout Plain Layout -vignette("Sweave", package = "utils") +## view the Sweave vignette (requires R >= 2.13.0) \end_layout \begin_layout Plain Layout -@ +vignette("Sweave", package = "utils") \end_layout \end_inset @@ -536,12 +614,22 @@ A simple example that will run in any S engine: \end_layout \begin_layout Standard -\begin_inset ERT +\begin_inset Flex Chunk +status open + +\begin_layout Plain Layout + +\begin_inset Argument 1 status open \begin_layout Plain Layout -<>= +print-integers, keep.source=TRUE +\end_layout + +\end_inset + + \end_layout \begin_layout Plain Layout @@ -551,32 +639,41 @@ status open \begin_layout Plain Layout -1:10 +1:10 \end_layout -\begin_layout Plain Layout +\end_inset + -@ \end_layout +\begin_layout Standard +\begin_inset Flex Chunk +status open + \begin_layout Plain Layout -<>= -\end_layout +\begin_inset Argument 1 +status open \begin_layout Plain Layout -## intentionally hide the output by setting results=hide +hide-results, results=hide +\end_layout + +\end_inset + + \end_layout \begin_layout Plain Layout -print(1:20) +## intentionally hide the output by setting results=hide \end_layout \begin_layout Plain Layout -@ +print(1:20) \end_layout \end_inset @@ -589,27 +686,32 @@ We can also emulate a simple calculator: \end_layout \begin_layout Standard -\begin_inset ERT +\begin_inset Flex Chunk status open \begin_layout Plain Layout -<>= -\end_layout +\begin_inset Argument 1 +status open \begin_layout Plain Layout -1 + pi +calculator +\end_layout + +\end_inset + + \end_layout \begin_layout Plain Layout -sin(pi/6) +1 + pi \end_layout \begin_layout Plain Layout -@ +sin(pi/6) \end_layout \end_inset @@ -622,12 +724,22 @@ Now we look at some Gaussian data: \end_layout \begin_layout Standard -\begin_inset ERT +\begin_inset Flex Chunk status open \begin_layout Plain Layout -<>= +\begin_inset Argument 1 +status open + +\begin_layout Plain Layout + +rnorm +\end_layout + +\end_inset + + \end_layout \begin_layout Plain Layout @@ -650,11 +762,6 @@ print(x) t1 <- t.test(x) \end_layout -\begin_layout Plain Layout - -@ -\end_layout - \end_inset @@ -753,22 +860,27 @@ iris \end_layout \begin_layout Standard -\begin_inset ERT +\begin_inset Flex Chunk status open \begin_layout Plain Layout -<>= -\end_layout +\begin_inset Argument 1 +status open \begin_layout Plain Layout -summary(iris[,-5]) +iris-summary +\end_layout + +\end_inset + + \end_layout \begin_layout Plain Layout -@ +summary(iris[,-5]) \end_layout \end_inset @@ -803,20 +915,22 @@ name "tab:xtable-demo" \end_inset -\end_layout +\begin_inset Flex Chunk +status open \begin_layout Plain Layout -\align center -\begin_inset ERT + +\begin_inset Argument 1 status open \begin_layout Plain Layout +xtable-demo,results=tex,echo=FALSE \end_layout -\begin_layout Plain Layout +\end_inset + -<>= \end_layout \begin_layout Plain Layout @@ -835,11 +949,6 @@ print(xtable(sapply(iris[,-5], quantile)), floating=FALSE) )') \end_layout -\begin_layout Plain Layout - -@ -\end_layout - \end_inset @@ -925,22 +1034,31 @@ Both eps and pdf are set to true so that both latex and pdflatex work. \end_inset -\begin_inset ERT +\end_layout + +\begin_layout Plain Layout +\align center +\begin_inset Flex Chunk status open \begin_layout Plain Layout -<>= -\end_layout +\begin_inset Argument 1 +status open \begin_layout Plain Layout -pairs(iris, col = iris$Species) +iris-pairs,fig=TRUE,width=4.5,height=4.5,eps=TRUE,pdf=TRUE +\end_layout + +\end_inset + + \end_layout \begin_layout Plain Layout -@ +pairs(iris, col = iris$Species) \end_layout \end_inset @@ -984,27 +1102,32 @@ status open \begin_layout Plain Layout \align center -\begin_inset ERT +\begin_inset Flex Chunk status open \begin_layout Plain Layout -<>= -\end_layout +\begin_inset Argument 1 +status open \begin_layout Plain Layout -par(mar=c(4,5,.1,.3), las=1) +iris-boxplots,fig=TRUE,width=7,height=2,keep.source=F,eps=T,pdf=T +\end_layout + +\end_inset + + \end_layout \begin_layout Plain Layout -boxplot(Sepal.Length~Species,data=iris,horizontal=TRUE,xlab='Sepal.Length') +par(mar=c(4,5,.1,.3), las=1) \end_layout \begin_layout Plain Layout -@ +boxplot(Sepal.Length~Species,data=iris,horizontal=TRUE,xlab='Sepal.Length') \end_layout \end_inset @@ -1221,7 +1344,8 @@ Sweave will use the filename of the Rnw file as the prefix string for the \begin_inset CommandInset href LatexCommand href name "#7551" -target "http://www.lyx.org/trac/ticket/7551" +target "https://www.lyx.org/trac/ticket/7551" +literal "false" \end_inset @@ -1408,8 +1532,9 @@ label= \end_layout \begin_layout Standard -Another known issue is the Sweave code chunk may fail when we change the - alignment of the chunk paragraph in \SpecialChar LyX +Another issue with the \SpecialChar TeX + code environment is the Sweave code chunk may fail + when we change the alignment of the chunk paragraph in \SpecialChar LyX (using \family sans Paragraph settings @@ -1461,25 +1586,10 @@ This is not a legitimate Sweave code chunk, since <<>>= \family default must start in a new line with nothing before it. - Therefore we recommend you to double check the real source code via -\family sans -View\SpecialChar menuseparator -View Source -\family default - when changing the alignment of a chunk paragraph, and make sure -\family typewriter -<<>>= -\family default - appears in a new line. - This explains why we manually added an empty line in the code chunk in - Table -\begin_inset CommandInset ref -LatexCommand ref -reference "tab:xtable-demo" - -\end_inset - -. + This does not happen when using the Chunk inset instead of the \SpecialChar TeX + code environmen +t. + \end_layout \begin_layout Section @@ -1487,13 +1597,13 @@ Resources \end_layout \begin_layout Standard -The homepage of Sweave is at +The user manual of Sweave is at \begin_inset Flex URL status collapsed \begin_layout Plain Layout -http://www.stat.uni-muenchen.de/~leisch/Sweave/ +https://stat.ethz.ch/R-manual/R-devel/library/utils/doc/Sweave.pdf \end_layout \end_inset @@ -1528,7 +1638,7 @@ status collapsed \begin_layout Plain Layout -http://www.lyx.org/MailingLists +https://www.lyx.org/MailingLists \end_layout \end_inset