Home Download Buy Blog Forum Support

R, sweave, and ST2

R, sweave, and ST2

Postby bmxican on Sat Nov 17, 2012 2:33 am

Hello all,

I recently made the switch from TextMate2 to SublimeText2 and I am really impressed with the editor so far. That said, I am still trying to get some of the functionality I had in TextMate in SublimeText2. I am going to outline two of the things I am trying to accomplish below with the hope that somebody can give me some advice.

1) I would like to be able to "sweave, typeset and view" a .Rnw file in the same way that I can in TextMate. The idea is that I can type cmd + R (cmd + B in ST2) and the R chunks are sent to R, sweaved, and then placed into a .tex file. That file is then compiled and SKIM is called to open the corresponding PDF file. My understanding is that I need to create a custom build in ST2 to do this. This is what I have so far:

Code: Select all
{
   "selector": ["source.Rnw"],

   "cmd": ["osascript", "-e", "tell app \"R64\" to cmd \"setwd('$file_path')\"\n",
                   "-e", "tell app \"R64\" to cmd \"Sweave('$file')\"\n"],


   "target": "make_pdf",
   "selector": "text.tex.latex",
   "osx":
   {
      "cmd": ["latexmk", "-cd",
            "-e", "\\$pdflatex = 'pdflatex %O -interaction=nonstopmode -synctex=1 %S'",
            //"-silent",
            "-f", "-pdf"],
      "path": "$PATH:/usr/texbin:/usr/local/bin",
      "file_regex": "^(...*?):([0-9]+): ([0-9]*)([^\\.]+)"
   }
}


Basically I am calling R, setting the working directory, and sweaving the .Rnw file. This part works fine. The .tex file is created and can be compiled if opened in ST2 independently. What I cannot do is make this build compile the .tex file after it is created. The second half of the code (from "target": "make_pdf", to the end) is copied from the LaTeX build. So any insight on how I can get this to work would be great. Now on to problem 2.

2) I would like to be able to use the Rconsole in one window and have my .R file in the other. I would like to build the .R file and have it sent to the R console in the first window. RIght now I am able to build the .R file, but the R.app is opened and the output is shown there, not in ST2. Any insight on how I could get this to work would also be appreciated. Thank you in advance.
bmxican
 
Posts: 6
Joined: Sat Nov 17, 2012 2:09 am

Re: R, sweave, and ST2

Postby bmxican on Wed Nov 21, 2012 3:53 am

Bump
bmxican
 
Posts: 6
Joined: Sat Nov 17, 2012 2:09 am

Re: R, sweave, and ST2

Postby AGS on Wed Nov 21, 2012 3:15 pm

Do you have SublimeREPL and LaTeXTools installed on your machine?
AGS
 
Posts: 32
Joined: Mon Aug 20, 2012 5:58 pm

Re: R, sweave, and ST2

Postby bmxican on Wed Nov 21, 2012 4:45 pm

Yes, I do. In fact, what I am trying to accomplish relies on SublimeREPL. I see it as the next logical step in order to bring the functionality of R in sublime text up to par with Textmate or R Studio.
bmxican
 
Posts: 6
Joined: Sat Nov 17, 2012 2:09 am

Re: R, sweave, and ST2

Postby AGS on Wed Nov 21, 2012 7:45 pm

Cool. I have just started to work on this, as well. I am more interested in 1st scenario you describe, as I don't think I'll be moving totally away from RStudio all that soon. But yes, writing/editing/compiling .Rnw in ST2 will be a great feature.
AGS
 
Posts: 32
Joined: Mon Aug 20, 2012 5:58 pm

Re: R, sweave, and ST2

Postby bmxican on Thu Nov 22, 2012 4:22 pm

I've put what I've done so far on Github. Please feel free to take a look and help out. I thought a lot more people would be wanting this type of functionality. Hopefully somebody who knows more than I do will be able to contribute.

https://github.com/jvcasill/Sweave-in-ST2
bmxican
 
Posts: 6
Joined: Sat Nov 17, 2012 2:09 am

Re: R, sweave, and ST2

Postby bmxican on Sat Dec 01, 2012 4:55 pm

I have found a solution to problem 2 on this website:

http://tomschenkjr.net/using-sublime-text-2-for-r/

The key was setting the path in the Sublime-REPL preferences to “/usr/bin/r”. Im still working on problem 1.
bmxican
 
Posts: 6
Joined: Sat Nov 17, 2012 2:09 am

Re: R, sweave, and ST2

Postby AGS on Sat Dec 08, 2012 4:55 am

Just started working on this, but what I have so far will compile the Sweave file and then the resulting .tex file and open skim to view it. Be advised this only has been tested/works on a mac.

Code: Select all
"{

    "cmd": ["bash", "-c", "/usr/bin/R64 CMD Sweave '${file_name}' && pdflatex '${file_base_name}.tex' -interaction=nonstopmode -synctex=1 %S -f -pdf && /Applications/Skim.app/Contents/MacOS/Skim '${file_base_name}.pdf'"],
    "path": "$PATH:/usr/texbin:/usr/local/bin",
    "selector": "text.tex.latex.sweave","shell":false,
    "file_regex": "^(...*?):([0-9]+): ([0-9]*)([^\\.]+)"
}


Obviously the goal will be to tie this into the awesome framework that is LaTeXtools.....
AGS
 
Posts: 32
Joined: Mon Aug 20, 2012 5:58 pm

Re: R, sweave, and ST2

Postby acc77 on Sun Jan 12, 2014 4:20 pm

This sounds good. Can someone please post steps (for newbies like myself) on how to get this working?
acc77
 
Posts: 3
Joined: Thu Jan 09, 2014 10:46 am


Return to Technical Support

Who is online

Users browsing this forum: No registered users and 41 guests