EDIT: had to retag this, because, it's rather a Sweave / R question since the problem of this script is the output directory of the Sweave Code. Is there a corresponding option for R CMD Sweave ?
I have a shell script that creates a .tex file from a .Rnw file. This file needs to be processed further, but is not found by the script because it's somehow automatically generated to my Home directory.
I need the .tex file to be generated in the folder of the .Rnw file (because all the other information is there). Note that the .Rnw file is what's usually selected with the file selector.
Side question: Is there an option for choose file, similar to JFileChooser in Java that enables only certain files for selecti开发者_如何学JAVAon?
Here's the code:
#!/bin/bash
myfile=$(/usr/bin/osascript << EOT
tell app "AppleScript Runner"
activate
return posix path of (choose file)
end
EOT)
if [ $? -eq 0 ]
then
R CMD Sweave $myfile
no_ext="${myfile%.*}"
/usr/local/texlive/2009/bin/universal-darwin/pdflatex $no_ext.tex
open $no_ext.pdf
else
echo "User canceled"
fi
Thx, to all those who helped with this initial script!
dirname
can be used to get the directory name of a file, or you can use the same sort of substitution you did earlier for the extension with /
instead.
filedir="${no_ext%/*}"
/usr/local/texlive/2009/bin/universal-darwin/pdflatex -output-directory "$filedir" "$no_ext.tex"
精彩评论