Persisting RStudio preferences
In the context of your runs, the RStudio user preferences (such as theme) are stored in a file located at /home/ubuntu/.rstudio/monitored/user-settings/user-settings. You can launch RStudio with custom preferences by modifying this file via the pre-setup script of a custom compute environment.
Method 1: Write lines to settings file
If you know the line you need to add to the settings file, you can write it directly in the pre-setup script. For example:
mkdir -p /home/ubuntu/.rstudio/monitored/user-settings/ echo 'uiPrefs={"theme" : "Mono Industrial"}' >> /home/ubuntu/.rstudio/monitored/user-settings/user-settings chown -R ubuntu:ubuntu /home/ubuntu/.rstudio if [ -f .domino/launch-rstudio-server ]; then sed -i.bak 's# > ~/.rstudio/monitored/user-settings/user-settings# >> ~/.rstudio/monitored/user-settings/user-settings#' .domino/launch-rstudio-server chown ubuntu:ubuntu .domino/launch-rstudio-server fi
Here's what each line is doing:
- The mkdir statement creates the encompassing directory.
- The echo statement writes the theme to the file. This can be replaced with a copy operation if you'd prefer to store a file in your project (see next section).
- The chown statements are needed to avoid a permissions error.
- The sed statement modifies a Domino script that would otherwise overwrite this settings file.
Method 2: Copy a saved settings file
If you aren't sure which lines to write, or if you want to persist this settings file in your project, you can save a copy in your project and use the following pre-setup script code to apply it to your session.
First, run a session and modify the RStudio preferences to your liking. Before you stop the session, copy the user-settings file to the root of your project directory. You can do so with this line of R code:
file.copy("/home/ubuntu/.rstudio/monitored/user-settings/user-settings", ".")
Then, add the following lines to the pre-setup script of your environment definition, in order to load the preferences file (if it exists) on subsequent runs:
if [ -f user-settings ]; then mkdir -p /home/ubuntu/.rstudio/monitored/user-settings/ cp user-settings /home/ubuntu/.rstudio/monitored/user-settings sed -i.bak '/initialWorkingDirectory=/d' /home/ubuntu/.rstudio/monitored/user-settings/user-settings chown -R ubuntu:ubuntu /home/ubuntu/.rstudio if [ -f .domino/launch-rstudio-server ]; then sed -i.bak 's# > ~/.rstudio/monitored/user-settings/user-settings# >> ~/.rstudio/monitored/user-settings/user-settings#' .domino/launch-rstudio-server chown ubuntu:ubuntu .domino/launch-rstudio-server fi fi
Note: the sed statement that deletes the "initialWorkingDirectory" variable is necessary to make sure your session starts with the correct working directory.
Comments
0 comments
Please sign in to leave a comment.