inlineOutputAddin provides an RStudio addin that evaluates selected R
code and inserts or updates a marked, commented output block directly in
an .R script.
This makes plain R scripts behave a bit like lightweight notebooks,
while remaining standard .R files.
You can install the development version from GitHub:
# install.packages("pak")
pak::pak("danielrak/inlineOutputAddin")Or using remotes:
remotes::install_github("danielrak/inlineOutputAddin")Given code like:
head(mtcars)Running the addin inserts (or updates) a marked output block:
head(mtcars)
# >>> output
# mpg cyl disp hp drat wt qsec vs am gear carb
# Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
# ...
# <<< outputIf the code changes and the addin is run again, the existing output block is automatically replaced.
-
Open an
.Rscript in RStudio. -
Select code (or place the cursor on a single line).
-
Run the addin:
- Via Addins → Update Inline Output
- Or assign a keyboard shortcut in:
Tools → Modify Keyboard Shortcuts
The function evaluates the code in the global environment and:
- Inserts a new output block if none exists
- Replaces the existing
# >>> output/# <<< outputblock if present
The addin uses the following markers:
# >>> output
# <<< output
Everything between them is treated as generated output and may be replaced on the next run.
- The addin requires RStudio.
- It captures printed console output.
- Long outputs are truncated for readability.
- It does not modify code outside the marked output block.
Because this functionality depends on RStudio, examples are guarded:
if (rstudioapi::isAvailable()) {
# dscript()
}Plain .R scripts are often preferred in institutional or production
settings.
This addin provides a lightweight way to keep code and results together
without switching to R Markdown or Quarto.
MIT © Daniel Rakotomalala