Search code examples
rsweave

How can I change the output directory of R CMD Sweave?


Using R CMD Sweave my .tex file is always generated in my HOME directory. Is it possible to change this? I mean i could mv it with a shell script, but I guess there`s some better trick to do it

@Dirk: I used the script that I posted here and pdflatex does not find the file because it's always written to the HOME directory of my user.


Solution

  • So here's what worked for me... No argument for R CMD Sweave but still a workaround. the use of basename and dirname helped a lot :)

    #!/bin/bash
    
    myfile=$(/usr/bin/osascript << EOT
    tell app "AppleScript Runner"
    activate
        return posix path of (choose file)
        end
        EOT)
    
        if [ $? -eq 0 ]
        then
            echo $myfile
            R CMD Sweave $myfile
            no_ext=`basename $myfile .Rnw`
            directory=`dirname $myfile`
            mv ~/$no_ext.tex $directory/$no_ext.tex
            /usr/local/texlive/2009/bin/universal-darwin/pdflatex -output-directory       $directory $no_ext.tex
            open $directory/$no_ext.pdf
            else
                echo "User canceled"
                fi