বৃহস্পতিবার, ২৯ আগস্ট, ২০১৩

Editing .Rnw file in with vim-r-plugin and insert-mode shortcut bug

When I started editing a sweave file with .Rnw extention, at the beginning it seemed everything is honky-dory. The latex-suite was loaded with the menus  along with R functionalities but ran into a wicked problem. Here in the tex.stackexchange.com forum I posted the problem:

http://tex.stackexchange.com/questions/130436/latex-suite-autocompletion-feature-not-working-with-rnw-file


I have been a great fan of Vim with its awesome Vim-latex suite providing extremely useful keybindings and autocompletion features. Then I installed vim-r-plugin and opened a .Rnw Sweave file. While syntax highlighting and other R related features such as key shortcuts are working fine, LaTeX shortcuts no longer works. For example, if I type SSE it longer gives "\section{}". But if I instead I open a .tex file, those shortcuts works just fine.
It's not that .Rnw files not detecting latex-suite in Vim. My latex suite is loaded with .Rnw files with all the menu and stuff. I can get the short cuts work with F5, F7 and alt keys. It's just that short cuts do not work in the insert mode. It's bugging me a lot and I have been on the hunt for a solution the whole day but could not find a fix yet.

I got this heavenly response with an elegant solution from  an user named FvD:

You need to associate the .Rnw files with tex.
The most direct way to do this is to issue the following command with the open .Rnw file:
:set filetype=tex
As soon as you have done that the vim-latex behaviour you are used to should be back. To incorporate this in a nice way in your vimrc is described here in a stackoverflow question. To wit:
autocmd BufRead,BufNewFile *.Rnw set filetype=tex
As per the vim-latex recommendations I also have
let g:tex_flavor="latex"
in my .vimrc, but that should not impact on the behaviour of the plugin itself (the filetype certainly does).

That was sweet indeed!

Work-around of a strange problem in vim-r-plugin

After installing the latex suite, my first task was to bring in the vim-r-plugin to edit noweb that is Sweave/knitr files. Following the installation instructions, whenever I tried to start R from Vim (/rf), the R started without any configuration I put in the .Rprofile ( see my earlier post). Then I had to actually make changes in the  Rprofile.site  file which is the  etc directory in the "Program Files" directory of R installation. Now whenever I call R  from Vim,  the configuration loads at the start-up.

মঙ্গলবার, ২৭ আগস্ট, ২০১৩

Configure .Rprofile for customizing R

Well, this has been bugging me a lot since I started using R, customizing start-up mechanism at R. Here is a great site which gives pretty good instructions on setting this up.

http://scs.math.yorku.ca/index.php/Rprofile

With notepad I created a file named .Rprofile with file extension  "all files". This is required because this is not a typical text even though you can open it with notepad. I put it in C:\R directory but you can put it in any directory you like but that has to be your startup directory. You can changes the startup directory by doing this:  right-click on the R icon, select Properties, and then change the Start In field to C:\R

With those instructions there I changes the prompt in R from "> " to "R> " by putting the following line in my  "C:\R\.Rprofile" file:

options(prompt="R> ")

I also had an long-standing issue where I had to always type my default library location. With .Rprofile this problem is gone. I simply add the following line in this .Rprofile file:

.libPaths("J:\\Rushad\\MOF\\R-stuff\\library")

The location of the directory above is my computer specification. It will differ from user to user.  

শনিবার, ২৪ আগস্ট, ২০১৩

Using Latex with Stata

Few days back I discovered a great tool for using LaTeX with Stata. Most of us are familiar with Sweave which is a package in R. I was very happy to find the utility to be used with  Stata. You can download it from here.

It's a .jar file, so you need to have java installed. I installed it it on my windows machine in root folder that is C:\ with a folder created named 'statweave'. After the installation, you have to adjust the statweave.cfg which is a configuration file. Specially look for your default LaTeX distribution, R and Stata installation folders address whether they are rightly located in the file.

To test whether it is working or not, I have created a separate folder which I guess can be anywhere on you computer. I downloaded some test files from here.

Another important aspect is that you should have Statweave.sty file in the same folder where your .swv or .tex file is. During the installation at one point you would be asked where you want to put your Statweave.sty file? I have chosen "C:\texlive\texmf-local\tex\latex\local". But everytime I run, it says that Statweave.sty is missing. Therefore I have copied it from that directory to the working directory where the .swv or .tex files are. Now it's working just fine.