More efficient R / Sweave / TeXShop work-flow?

后端 未结 11 928
傲寒
傲寒 2021-01-30 05:28

I\'ve now got everything to work properly on my Mac OS X 10.6 machine so that I can create decent looking LaTeX documents with Sweave that include snippets of R code, output, an

相关标签:
11条回答
  • 2021-01-30 06:07

    Just a note: you can actually call things like pdflatex etc. directly from R using texi2dvi (in the tools package). For example:

    Sweave(file="/Users/mymachine/Documents/Assign4.Rnw")
    
    texi2pdf("Assign4.tex")
    

    would compile your Rnw file into a pdf. Thus, no need to leave R to handle the tex->pdf step.

    0 讨论(0)
  • 2021-01-30 06:14

    I use these (saved as sweave.engine and sweavebibtex.engine) for custom engines in texshop. I usually work up a code chunk in R, then copy the block into the rnw file I have open in texshop. I'd love a solution that lets me do syntax highlighting and spelling correction of R and tex in the same document (that isnt emacs).

    #!/bin/bash
    echo 'SWEAVE | PDFLATEX. Custom engine--Akasurak-16Nov2009'
    export PATH=$PATH:/usr/texbin:/usr/local/bin
    R CMD Sweave "$1"
    pdflatex "${1%.*}"
    

    and the second, for doing bibtex as well:

    #!/bin/bash
    date
    before="$(date +%s)"
    echo 'SWEAVE | PDFLATEX | BIBTEX | PDFLATEX | PDFLATEX. Custom engine--Akasurak-16Nov2009'
    #Updated 20Jul2010 for auto including Sweave.sty
    
    
    export PATH=$PATH:/usr/texbin:/usr/local/bin
    
    R CMD Sweave "$1"
    R CMD pdflatex "${1%.*}"
    bibtex  "${1%.*}.aux"
    R CMD pdflatex "${1%.*}"
    R CMD pdflatex "${1%.*}"
    
    
    after="$(date +%s)"
    elapsed_seconds="$(expr $after - $before)"
    date
    echo Elapsed time '(m:s)': $(date -r $elapsed_seconds +%M:%S)
    

    Can't say they are the best way of doing things, but they do work.

    0 讨论(0)
  • 2021-01-30 06:17

    On the bash shell command line:

    R CMD Sweave foo.Rnw && pdflatex foo.tex
    

    Runs Sweave, and if that succeeds it goes on to do pdflatex. Out pops a pdf. If you've got this in a bash Terminal then just hit up-arrow to get it back and do it again. And again. And Again.

    Makefile solution also good.

    0 讨论(0)
  • 2021-01-30 06:17

    RStudio has a button that does this in one go. One caveat is that it runs in its own session, so any workspace variables you may have set are ignored.

    the compile button

    0 讨论(0)
  • 2021-01-30 06:17

    The best solution is here: you create a new *.engine for TeXShop to use, then typeset using the shortcut or the 1 button.

    http://cameron.bracken.bz/sweave-for-texshop

    Cameron is also very responsive, so I highly recommend his solution.

    0 讨论(0)
  • 2021-01-30 06:20

    One-click Sweaving is easy to do in TeXShop using the Sweave.sh script by Gregor Gorjanc. Get it from http://cran.r-project.org/contrib/extra/scripts/Sweave.sh and put it in your ~/Library/TeXShop/bin/ folder.

    Then add the following files to your ~/Library/TeXShop/engines/ folder:

    As Sweave.engine:

    #!/bin/bash
    ~/Library/TeXShop/bin/Sweave.sh  -ld "$1"
    

    As SweaveNoClean.engine:

    #!/bin/bash
    ~/Library/TeXShop/bin/Sweave.sh  -nc -ld "$1"
    

    You'll have to set the permissions on Sweave.sh and the two engine files to allow execution.

    To Sweave with one click, restart TeXShop after adding these files, open the Sweave document (with Rnw extension) and in the dropdown menu above the document window, change it from LaTeX to Sweave or SweaveNoClean.

    BEWARE: The "Sweave" option wll clean up after itself, deleting all the extra files LaTeX and Sweave creates. If your file is called myfile.Rnw, this will include files called myfile.R and myfile.tex. So a word to the wise: make sure the basename of your Rnw file is unique; then nothing unexpected will be written over and then deleted.

    The SweaveNoClean option does not clean up after itself. This makes sure you don't delete anything unexpected; though it could still write over a file called myfile.tex if you Sweave a myfile.Rnw. This also doesn't delete any graphics that have been created, in case you want to have them separate from your full typeset document.

    0 讨论(0)
提交回复
热议问题