Print the sourced R file to an appendix using Sweave

后端 未结 4 1813
鱼传尺愫
鱼传尺愫 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条回答
  •  滥情空心
    2021-01-03 13:01

    You can use highlight package to output nicely formatted, colorful code:

    highlight("myRfile.R", renderer = renderer_latex(document = F))
    

    But don't forget to put in your latex doc the lengthy preamble which you get with document=T.

    You can experiment with code directly:

    highlight(output="test.tex", 
              parser.output = parser(text = deparse(lm)),
              renderer =  renderer_latex(document = T))
    

    And get

    alt text

提交回复
热议问题