Print the sourced R file to an appendix using Sweave

后端 未结 4 1798
鱼传尺愫
鱼传尺愫 2021-01-03 12:53

I keep R and Rnw files separate, then load the R data/plots with load(\"file.R\") in the first Sweave chunk. Is there a way that I can print the sourced R file

4条回答
  •  萌比男神i
    2021-01-03 13:09

    I usually solve this by:

    \begin{appendix}
    
    \section{Appendix A}
    
    \subsection{R session information}
    
    <>=
    
    toLatex(sessionInfo())
    
    @
    
    
    \subsection{The simulation's source code}
    
    <>=
    
    Stangle(file.path("Projectpath","RnwFile.Rnw"))
    
    SourceCode <- readLines(file.path("Projectpath","Codefile.R"))
    
    writeLines(SourceCode)
    
    @
    \end{appendix} 
    

    Using this you have to think of a maximum numbers of characters per line.

提交回复
热议问题