Skip to content

Instantly share code, notes, and snippets.

@jimbrig
Last active September 7, 2020 03:23
Show Gist options
  • Save jimbrig/36bcdec179de1da173639e6e786993d6 to your computer and use it in GitHub Desktop.
Save jimbrig/36bcdec179de1da173639e6e786993d6 to your computer and use it in GitHub Desktop.
[R Setup Script] A collection of scripts helpful for expiditing the initial setup and configuration of R, RStudio, RTools, and other libraries in Windows 10. #setup #r #rstudio #config #windows10 #powershell #command-line #bash #r-package
# ------------------------------------------------------------------------
#
# Title : R Configuration / Setup Script
# By : Jimmy Briggs
# Date : 2019-12-20
#
# ------------------------------------------------------------------------
# NOTE: This script should be run in RStudio as an Admin...
# install packages --------------------------------------------------------
if (!require(pacman)) install.packages("pacman")
pacman::p_load(devtools,
installr,
tinytex,
rstudioapi,
magrittr,
dplyr,
pkgbuild)
rstudioapi::restartSession()
# configure RStudio settings ----------------------------------------------
# disable reloading of workspace between sessions
usethis::use_blank_slate(scope = "user")
# review system environment variables:
Sys.getenv()
# configure your R library path for R packages
.libPaths()
# copy packages to new R-version's windows library
libdir_prior <- file.path("<enter prior win-library path here>")
libdir_current <- file.path("<enter current win-library path here>")
installr::copy.packages.between.libraries(
from = libdir_prior, to = libdir_current
)
# check
.libPaths()[1] == libdir
# configure dotfiles .Rprofile & .Renvrion --------------------------------
# review dotfiles
usethis::edit_r_environ(scope = "user") # (RTools Path, github PAT, keys, etc.)
usethis::edit_r_profile(scope = "user") # (various options for packages)
# additional software ---------------------------------------------
pkgbuild::setup_rtools()
# Rtools
installr::install.rtools()
rstudioapi::restartSession()
writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron")
# git
installr::install.git()
rstudioapi::restartSession()
# tinytex
tinytex::install_tinytex()
rstudioapi::restartSession()
tinytex::use_tinytex()
tinytex:::is_tinytex()
install.packages("blogdown")
blogdown::install_hugo()
# java
installr::install.java()
# pandoc
installr::install.pandoc()
# node.js (only if desired)
installr::install.nodejs()
# github Git Client (only if desired)
installr::install.github()
# inno (only if desired)
installr::install.inno()

rscodeio

An RStudio theme inspired by Visual Studio Code.

Prerequisites

RStudio 1.2.x or higher.

Installation

Get the package:

remotes::install_github("anthonynorth/rscodeio")

rscodeio modifies the theme of RStudio menus. These are not exposed by the current theming API and so this is achieved by modifying style sheets in the RStudio installation. To modify files in this area will likely require the installation to be run with administrator privileges. To do this:

  • On Windows start RStudio by right clicking on a shortcut or menu icon and selecting 'Run as Administrator'
  • On Linux start RStudio in a terminal using sudo rstudio --no-sandbox
  • On Mac this is not required. Theming the menus is not supported.
    • They're inherited from OS so might want to use your dark OS theme.

From within RStudio running as administrator, run this command to install and apply the theme:

rscodeio::install_theme()

And close RStudio. Reopen it in the normal way and the theme should be fully applied.

Once installed it can also be selected using the RStudio theme picker in the usual way.

Recommended RStudio settings

For best results, make sure the following settings are enabled:

  • ToolsGlobal Options…CodeDisplay☑ Highlight selected line
  • ToolsGlobal Options…CodeDisplay☑ Show indent guides
  • ToolsGlobal Options…CodeDisplay☑ Show syntax highlighting in console input
  • ToolsGlobal Options…CodeDisplay☑ Highlight R function calls

Switching to another theme

rscodeio modifies UI elements that are not part of standard theming. This means the RStudio file menus will remain dark even if you switch to another theme. To revert them, within an RStudio session run as administrator, use: rscodeio::deactivate_menu_theme. Reactivate again with: rscodeio::activate_menu_theme.

Supported Platforms

rscodeio has only been tested on Windows and Pop!_OS Linux so far. Feedback from other platforms welcome.

# if (!require(githubinstall)) install.packages("githubinstall")
# githubinstall::gh_install_packages("rscodeio")
remotes::install_github("anthonynorth/rscodeio")
# start RStudio as Admin
rscodeio::install_theme()
# activate / unactivate functions
rscodeio::deactivate_menu_theme()
rscodeio::activate_menu_theme()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment