Quick Tip : RServe tricks that can make your life easier

October 18, 2016
By

(This article was first published on R – Bora Beran, and kindly contributed to R-bloggers)

RServe offers a number of configuration options that can come in handy when working with R inside Tableau but they are not captured in detail in RServe’s documentation. Let’s talk about a few.

How can I start RServe with a configuration file in a custom location?

RServe has a default place for the placement of configuration file e.g. /etc/Rserv.conf on Linux/Mac but you may not want to use that location or even have multiple config files that you switch sometimes so it is much more convenient to explicitly set it.

You can do this in the following way when starting RServe from R:

On Windows

Rserve(args="--RS-conf C:\\PROGRA~1\\R\\R-215~1.2\\library\\Rserve\\Rserv.cfg")

On Linux/Mac

Rserve(args=" --no-save --RS-conf ~/Documents/Rserv.cfg")

You can also do this from command line/terminal window. Assuming Rserve.exe is in the path or you’re in the folder that contains Rserve.exe so Rserve would be recognized:

Rserve –-RS-conf C:\\Users\\bberan\\Rserv.cfg

You probably noticed that on Mac there is an extra argument “--no-save”. On Mac starting RServe requires using one of --save,--no-save or --vanilla but what do they mean? The answer is in R help

BBERAN-MAC:~ bberan$ R --help
Usage: R [options] [< infile] [> outfile]
or: R CMD command [arguments]
Start R, a system for statistical computation and graphics, with the specified options, or invoke an R tool via the 'R CMD' interface.
Options:
--save                Do save workspace at the end of the session
--no-save             Don't save it
--no-environ          Don't read the site and user environment files
--no-site-file        Don't read the site-wide Rprofile
--no-init-file        Don't read the user R profile
--restore             Do restore previously saved objects at startup
--no-restore-data     Don't restore previously saved objects
--no-restore-history  Don't restore the R history file
--no-restore          Don't restore anything
--vanilla             Combine --no-save, --no-restore, --no-site-file,--no-init-file and --no-environ

Config files are very useful since they provide a centralized place to pre-load all the libraries you need so you don’t have to load them as part of each request which results in better performance, they allow evaluating any R code as part of RServe startup allowing you to load trained models or R script files, even data that you may want to use as part of your analysis when running  R code from Tableau.

How can I debug R scripts I have in Tableau by taking advantage of my R development environment?

As you’re writing scripts in Tableau, you may want to understand different steps data is going through especially if you’re getting errors when script is being evaluated. There are many ways to debug. Using RServe in debug mode (Rserve_d.exe) outputs all the exchanges into the command line and can be a a bit verbose. You can also insert statements like write.csv in your script to create output of different data structures but by favorite option is to do this using an environment like the basic R GUI or RStudio.

On Linux/Mac

If you started Rserve from your R console the way described in the beginning, you can insert print statements to print into the console and even your plot statements will create visuals in R (if you have X11 installed) which can come in handy when debugging large and complex chunks of R code.

On Windows

You can achieve the same by starting R using:

run.Rserve(args="--no-save")

This takes over the current R session and makes it into an Rserve session as opposed to starting it by typing RServe() which starts a new Rserve process by calling Rserve.exe.

I hope you find this useful.

To leave a comment for the author, please follow the link and comment on their blog: R – Bora Beran.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)