1

使用 R CMD Sweave 我的 .tex 文件总是在我的 HOME 目录中生成。有可能改变这个吗?我的意思是我可以用 shell 脚本 mv 它,但我想有一些更好的技巧可以做到这一点

@Dirk:我使用了我在此处发布的脚本,但pdflatex 找不到该文件,因为它始终写入我用户的 HOME 目录。

4

2 回答 2

0

嗯?它始终在当前工作目录中。所以试试

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

现在whatever.tex将是~/foo因为那是您 a) 放置源和 b) 调用命令的地方。

于 2010-08-18T13:52:43.820 回答
0

所以这对我有用...... R CMD Sweave 没有论据,但仍然是一种解决方法。使用 basename 和 dirname 有很大帮助 :)

#!/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
于 2010-08-18T15:10:47.193 回答