<jupyter_start><jupyter_text>Setup notebooksIf you don't already have a setup notebook in your workspace, copy this notebook to your workspace.In your workspace, run this notebook before running any other R notebooks.This notebook needs to be rerun when your cluster is recreated. (This is rare -- when you stop using a notebook, your VM is paused, not deleted. Your cluster only recreates after you click the "Delete cluster" button.)  R environment setupIn this notebook we install a collection of R packages and Jupyter extensions above and beyond what is installed by default on Leonardo. These are packages used in one or more of the notebooks in this workspace.  Install R packages<jupyter_code>install_if_missing <- function(packages) {
    if (length(setdiff(packages, rownames(installed.packages()))) > 0) {
        install.packages(setdiff(packages, rownames(installed.packages())))
    }
}<jupyter_output><empty_output><jupyter_text>Generally useful R packages<jupyter_code>install_if_missing(c('tidyverse', 'viridis', 'ggthemes', 'qwraps2', 'pryr', 'skimr',
                     'testthat', 'reticulate', 'data.table', 'RCurl','stringr'))<jupyter_output><empty_output><jupyter_text>Install notebook extensions<jupyter_code># TODO Remove this after https://github.com/DataBiosphere/leonardo/issues/404
system('pip install jupyter_contrib_nbextensions 2>&1', intern = TRUE)
LOCATION <- system('pip show jupyter_contrib_nbextensions | grep Location | awk \'{print $2}\'', intern = TRUE)
LOCATION<jupyter_output><empty_output><jupyter_text>Code folding extension<jupyter_code>system(stringr::str_glue('jupyter nbextension install {LOCATION}/jupyter_contrib_nbextensions/nbextensions/codefolding --user 2>&1'),
       intern = TRUE)
system('jupyter nbextension enable codefolding/main 2>&1', intern=TRUE)<jupyter_output><empty_output><jupyter_text>Collapsible headings extension<jupyter_code>system(stringr::str_glue('jupyter nbextension install {LOCATION}/jupyter_contrib_nbextensions/nbextensions/collapsible_headings --user 2>&1'),
       intern = TRUE)
system('jupyter nbextension enable collapsible_headings/main 2>&1', intern=TRUE)<jupyter_output><empty_output><jupyter_text>Confirm that the R packages load properly<jupyter_code>library(qwraps2)    # Function summary_table() is the replacement for output formating for the Table1 Macro.
library(viridis)    # A nice color scheme for plots.
library(ggthemes)   # Common themes to change the look and feel of plots.
library(scales)     # Graphical scales map data to aesthetics in plots.
library(testthat)   # Testing functions.
library(assertthat) # Assertion functions.
library(pryr)       # Memory usage functions.
library(skimr)      # Summary statistics for dataframes.
library(bigrquery)  # BigQuery R client.
library(tidyverse)  # Data wrangling packages.
library(reticulate) # Python R client.

library(Ronaldo)    # Leonardo R package.<jupyter_output>Loading required package: viridisLite

Attaching package: ‘scales’

The following object is masked from ‘package:viridis’:

    viridis_pal


Attaching package: ‘skimr’

The following object is masked from ‘package:testthat’:

    matches

The following object is masked from ‘package:stats’:

    filter

── [1mAttaching packages[22m ─────────────────────────────────────── tidyverse 1.2.1 ──
[32m✔[39m [34mggplot2[39m 3.1.0       [32m✔[39m [34mpurrr  [39m 0.3.2  
[32m✔[39m [34mtibble [39m 2.1.1       [32m✔[39m [34mdplyr  [39m 0.8.0.[31m1[39m
[32m✔[39m [34mtidyr  [39m 0.8.3       [32m✔[39m [34mstringr[39m 1.4.0  
[32m✔[39m [34mreadr  [39m 1.3.1       [32m✔[39m [34mforcats[39m 0.4.0  
── [1mConflicts[22m ────────────────────────────────────────── tidyverse_conflicts() ──
[31m✖[39m [34mreadr[39m::[32mcol_factor()[39m masks [34mscales[39m::col_factor()
[31m✖[39m [34mpurrr[39m::[32mcompose()[39m    masks [34mpryr[39m::compose()
[31m✖[39m[...]<jupyter_text>TroubleshootingThis notebook installs the most recent versions of R packages from [CRAN](https://cran.r-project.org/) and Python packages from [pip](https://pypi.org/project/pip/) on to your VM. Additionally, some packages come from [GitHub](https://github.com/) or [Cloud Source Repositories](https://cloud.google.com/source-repositories/).1. If you encounter any errors, first just try `Kernel -> Restart & Run All`.1. If an R package still fails to install: 1. open a terminal by clicking on the terminal icon next to 'Notebook Runtime' in the upper top right corner of the window 1. type `R` to start R in the terminal 1. type `install.packages("qwraps2")` to get a more detailed error message. Replace `qwraps2` with the name of which ever package is failing to install.1. If that error message tells you what you need to do to resolve the issue, great! If not, copy and paste the error message into Google Search for more help.   Provenance<jupyter_code>devtools::session_info()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12893462469733658, 'fraction_numerical': 0.033292978208232446, 'mean_word_length': 5.556878306878307, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 35, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '394916', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1799, 'n_tokens_neox': 1615, 'n_words': 472, 'path': 'terra-notebooks-playground/R environment setup .ipynb', 'repo_name': 'akovalsk/notebooks', 'size': '4956'}