MyNixOS website logo
Description

Extract External 'R' Code and Insert Inline.

An 'RStudio' and 'Positron' add-in that prompts the user for a web 'URL', fetches the page content, extracts 'R' code chunks, and inserts those code chunks into the active editor at the current cursor position. Supports extraction of raw 'Markdown' or 'Quarto' source files, 'GitHub' Gist and rendered 'HTML' pages that have markup elements with 'R'-related classes.

ctrlvee

Lifecycle: experimental R-CMD-check

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.

Overview

Motivation

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 ...

Solution

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.

Setup

Installation

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")

Keyboard shortcuts

ctrlvee is written as an add-in for Positron and RStudio. For easiest access, consider configuring a keyboard shortcut:

  • Positron: Command Palette → search "Extract External R Code"
  • RStudio: Tools → Modify Keyboard Shortcuts → search "Extract External R Code"

Usage

Quick start

  1. Install ctrlvee
  2. Open any .R script in Positron or RStudio
  3. Place your cursor where you want code inserted
  4. Addins → Extract External R Code and Insert Inline (or your keyboard shortcut).
  5. Paste a URL (e.g., rendered Quarto chapter like https://dstt.stephenturner.us/validation.html)
  6. Code appears at your cursor with comments about provenance

Alternatives

ctrlvee 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")

Limitations

Development status

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.

Using code from external sources

  • Provenance: If you're extracting external code, you should know where it comes from. While 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.
  • Licenses: Before reusing extracted content in your own work, always verify the source's license. Just because it is available, does not necessarily mean it is appropriate to be used for what you have in mind. Always read the license.
  • Dependencies: It's common to find code that is distributed without explicitly including steps to install dependencies. Don't forget that step when you try to run the code on your system. And of course keep in mind that dependencies may no longer be available and/or versions might have changed since the code was published.
Metadata

Version

0.1.0

License

Unknown

Platforms (80)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows