ctrlvee lets you fetch R code from a URL and insert it
directly into your editor. It is built as an add-in for Positron and
RStudio, so you can pull code from web books, blog posts, vignettes,
READMEs, and other online sources without copying and pasting by
hand.
Install ctrlvee from CRAN:
Or from GitHub with pak:
The recommended way to use ctrlvee is through the IDE
add-in.
Here is the typical workflow:
.R script in Positron or RStudioYou may want a keyboard shortcut for easier access to the add-in. The steps depend on your IDE:
Stritcly speaking, you don’t have to use the add-in. The package includes exported functions that you can call from the console or from your own scripts.
crawl_chunks() is the main workhorse of
ctrlvee. It will fetch the contents of a URL, detect what
kind of source it is, and return the R code it finds:
ctrlvee decides how to parse a page by detecting a
“strategy”. Rendered HTML pages (like a Quarto book or an RMarkdown
vignette) are handled differently from raw source files (like an
.Rmd or .qmd on GitHub).
You can see which strategy ctrlvee would choose for a
given URL:
## check the detected strategy for a rendered page
detect_strategy("https://dstt.stephenturner.us/validation.html")You can override the strategy used if needed:
When ctrlvee inserts code into your editor, it includes
a comment at the top that records the source URL. This is intentional.
Knowing where code comes from is important for reproducibility.
Before running extracted code, keep the following in mind:
To get a feel for what ctrlvee can do, the table below
provides some example URLs to try. They are organized by source type so
you can see the range of content that ctrlvee handles.
| Type | Source | URL |
|---|---|---|
| Book | Data Science Team Training: Data Validation and QA | https://dstt.stephenturner.us/validation.html |
| Book | Text Mining with R: Topic Modeling | https://www.tidytextmining.com/topicmodeling |
| Book | The Epidemiologist R Handbook: Transmission Chains | https://epirhandbook.com/en/new_pages/transmission_chains.html |
| pkgdown vignette | ggplot2: Aesthetic Specifications | https://ggplot2.tidyverse.org/articles/ggplot2-specs.html |
| pkgdown vignette | tidyr: Pivoting | https://tidyr.tidyverse.org/articles/pivot.html |
| pkgdown vignette | stringr: Regular Expressions | https://stringr.tidyverse.org/articles/regular-expressions.html |
| Raw source | dplyr: Two Tables Vignette | https://raw.githubusercontent.com/tidyverse/dplyr/refs/heads/main/vignettes/two-table.Rmd |
| Raw source | pracpac: Basic Usage Vignette | https://raw.githubusercontent.com/signaturescience/pracpac/refs/heads/main/vignettes/basic-usage.Rmd |
| Raw source | Example Outbreak Animation Gist | https://gist.github.com/vpnagraj/b6c79f1a9b51166668649fa7ff28d3fb |