代码之家  ›  专栏  ›  技术社区  ›  Matt Bannert

如何更改R CMD swave的输出目录?

  •  1
  • Matt Bannert  · 技术社区  · 15 年前

    使用R CMD swave,我的.tex文件总是在我的主目录中生成。有可能改变这个吗?我的意思是我可以用一个shell脚本来录制它,但我想还有更好的技巧

    @德克: 我用了我贴的剧本 here

    2 回复  |  直到 8 年前
        1
  •  0
  •   Dirk is no longer here    15 年前

    呵呵?总是在黑暗中 当前工作目录 . 所以试试看

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

    whatever.tex 现在是 ~/foo

        2
  •  0
  •   Matt Bannert    15 年前

    这就是我的工作。。。R CMD swave没有参数,但仍然是一个解决方法。 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