Clusydocs
Guides

R notebooks

Write and run R cells, install packages, share data, and branch an analysis.

Choose R from the language selector on a code cell. Write ordinary R code; Clusy runs it in the branch's R session and displays the output below the cell. Code completion, inline edits, and code generated from a text description use the selected language.

measurements <- data.frame(
  group = rep(c("control", "treatment"), each = 4),
  value = c(3, 5, 4, 6, 7, 8, 6, 9)
)
aggregate(value ~ group, measurements, mean)

Later R cells can use measurements, functions, loaded packages, and other objects from earlier cells. Python and R have separate variable namespaces. Changing a cell's language changes how its source runs; it does not translate the source or copy variables between languages.

If another collaborator changes the language while you are editing or generating code, Clusy keeps your draft and pauses saving and running it. Choose the intended language or review and edit the draft before continuing.

Packages and plots

R is included in every sandbox stack, on CPU and GPU. Common packages include ggplot2, dplyr, tidyr, readr, jsonlite, htmlwidgets, and plotly. Install additional packages using R:

install.packages("broom", repos = "https://cloud.r-project.org")
library(broom)

The default user library is R/library in the branch workspace, so installed packages are included when workspace files are saved or copied to a branch. Packages requiring extra operating-system libraries may need those dependencies installed first. Compiled packages may need reinstalling after a runtime change.

Base R plots and ggplot2 figures appear as images. Data frames appear as tables, and HTML widgets display inline.

library(ggplot2)
ggplot(measurements, aes(group, value, fill = group)) +
  geom_boxplot() +
  theme_minimal()

Work with Python

Use files in the branch workspace to exchange data between languages. For example, save a CSV in an R cell:

write.csv(measurements, "measurements.csv", row.names = FALSE)

Read it in a Python cell:

import pandas as pd
measurements = pd.read_csv("measurements.csv")

Branches, stops, and restores

Ordinary R cells reuse the same R process, including live connections. A branch copy or cold restore recovers serialized R objects, functions, package attachments, options, and random-number state along with the branch's saved files. Sibling branches have separate R sessions.

Connections and native resources such as external pointers cannot be recovered by R serialization. Variables containing connections, including lists, environments, and closures, are omitted from saved state and reported by name; their live values remain available in the current session. Recreate omitted resources after restoration. A connection stored in an option prevents saving a safe checkpoint; remove that option before saving again. Other nested native resources may also require reconstruction.

Stopping a cell preserves completed changes when R responds to the interrupt. If a worker exits or must be forcibly stopped, recovery uses its last saved state.

Import, export, and Git

Import an R .ipynb through the notebook menu. R notebooks export with the standard ir kernelspec for IRkernel. Notebooks containing both languages preserve each cell's language in Clusy metadata and require Clusy to execute both languages.

Git sync writes a Python-only branch as .py, an R-only branch as .R, and a mixed branch as .clusy. These files use percent cell markers; the manifest preserves notebook and branch structure. Keep the clusy_id and clusy_language markers when editing cells outside Clusy.

Ordinary # %% comments are preserved inside source. Lines containing valid Clusy cell-marker metadata are reserved as cell boundaries.

On this page

Ask docs