tags:

views:

40

answers:

2

The question title says it all. 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.

A: 

Huh? It's always in the current working directory. So try

 mkdir foo
 mv whatever.Rnw foo
 cd foo
 R CMD Sweave whatever.Rnw

and whatever.tex will now be ~/foo because that is where you a) put the source and b) invoked the command.

Dirk Eddelbuettel
just edit my question to point to the script in a link. The script opens a dialog box where I can choose the .Rnw file (Mac OSX) .
ran2
Then you may have a) a problem with that script and/or your path and b) a particularly ill-worded question as `R CMD Sweave` is not at fault.
Dirk Eddelbuettel
I am not blaming `R CMD Sweave` :) . Though if there was an argument for the output directory I could use it instead of ´mv´ the files. Indeed the problem is that $myfile is the whole posix path as it's returned from the osascript and I have trouble splitting it correctly. But the only reason I have to split is because I need to mv things around (because of R CMD).
ran2
A: 

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
ran2
@Dirk, it's strange because also within my R Code I never use HOME as a wd.
ran2
For the first time I was even able to make this code work with platypus.
ran2