Fetch R code from an external source and insert it directly in an editor. Built as an add-in for integrating with Positron and RStudio.
You’re reading a web book (or blog post, vignette, README, etc) and you see some R code you want to try out. How do you get that into your editor? Sure, you might just copy/paste. But that can be tedious and error-prone, especially for documents that have code split across multiple chunks.
Is there an easier way to go out and pull the code from an external source so you can run it on your computer?
Enter ctrlvee …
ctrlvee provides functionality to parse R code from a
given URL that contains either rendered R chunks (e.g., Quarto book,
RMarkdown vignette, GitHub README) or “raw” R code (e.g., Rmd/Qmd/Md,
files with fenced chunks, R script in a Gist). The Positron/RStudio
add-in provided in this package will insert the parsed code directly
into the editor so you can run it on your system.
To install ctrlvee from CRAN:
install.packages("ctrlvee")You can install the development version of ctrlvee by
cloning the repo and installing from source.
Alternatively, install from GitHub with a tool like
pak:
pak::pkg_install("vpnagraj/ctrlvee")ctrlvee is written as an add-in for Positron and
RStudio. For easiest access, consider configuring a keyboard
shortcut:
ctrlvee.R script in Positron or RStudioctrlvee is recommended for use as an IDE add-in. But you
can use the exported package functions programatically too.
For example:
library(ctrlvee)
## crawl code chunks and auto-detect strategy from URL
crawl_chunks("https://dstt.stephenturner.us/validation.html")
## crawl code chunks and force a specific strategy
crawl_chunks("https://dstt.stephenturner.us/validation.html", strategy = "html")
## see the just the strategy detection in action
detect_strategy("https://dstt.stephenturner.us/validation.html")NOTE: The ctrlvee package is currently
experimental. YMMV. With that said, please use the GitHub issue
queue to report issues and/or suggest new features.
ctrlvee will include
a provenance statement, you should look before you leap. Make sure you
know understand where the code is coming from before running it.