Chapter 7 Setting Your R Profile

When developing on the RStudio server instance on your Spark HDInsight Cluster, it might be useful to configure your profile so that your R environment can find the SparkR library. This can save some tedious operations that can easily be missed, or mistyped.

Here is an example .Rprofile, specifying the location of the SparkR library. If you prefer not to load the SparkR library by default, or change your user Rprofile, you can load the package directly from it’s directory before conducting your analysis. Details of doing this are provided in the following chapter.

.First <- function() {
  .libPaths(c(file.path(Sys.getenv("SPARK_HOME"), "R", "lib"), .libPaths()))
  pkgs_to_load <- c(getOption("defaultPackages"), "SparkR")
  options(defaultPackages = pkgs_to_load)


.Last <- function() {
    if (interactive()) {
        hist_file <- Sys.getenv("R_HISTFILE")
        if (hist_file == "")
            hist_file <- "~/.RHistory"

For more information about your user Rprofile, see the R documentation on startup configurations: help(Startup).