Skip to content

catcall: insert generated code directly into active RStudio document#15

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/update-catcall-functionality
Draft

catcall: insert generated code directly into active RStudio document#15
Copilot wants to merge 2 commits into
mainfrom
copilot/update-catcall-functionality

Conversation

Copilot AI commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

catcall() only printed reconstructed object code to the console, requiring a manual copy-paste into the active document.

Changes

  • R/catcall.R: When RStudio is available, catcall() now calls rstudioapi::insertText() to place the generated code at the current cursor position, then returns invisibly. Falls back to the existing console print behavior when RStudio is unavailable. Uses a rdstools.insert_text_fun option override (consistent with rdstools.restart_session_fun pattern) to keep it testable without RStudio.

  • tests/testthat/test-catcall.R: Replaces the single console-output test with two explicit paths — non-RStudio (console fallback) and RStudio (insertion + invisible return verification).

Usage

# In an RStudio session, calling catcall() now inserts code at the cursor:
x <- c("a", "b", "c")
catcall(x)
# → inserts: c("a", "b", "c") directly into the active document

# Outside RStudio, behavior is unchanged — prints to console

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cloud.r-project.org
    • Triggering command: /usr/lib/R/bin/exec/R /usr/lib/R/bin/exec/R --no-echo --no-restore -e install.packages(&#39;devtools&#39;) d64.deb (dns block)
  • cran.r-project.org
    • Triggering command: /usr/lib/R/bin/exec/R /usr/lib/R/bin/exec/R --vanilla --slave -e options(repos=c(CRAN=&#39;REDACTED&#39;));~&#43;~install.packages(c(&#39;roxygen2&#39;,~&#43;~&#39;devtools&#39;,~&#43;~&#39;testthat&#39;),~&#43;~dependencies=TRUE) buntu0.2_amd64.deb (dns block)
    • Triggering command: /usr/lib/R/bin/exec/R /usr/lib/R/bin/exec/R --vanilla --slave -e chooseCRANmirror();~&#43;~install.packages(&#39;devtools&#39;,~&#43;~dependencies=TRUE) (dns block)
  • mirror.example.com
    • Triggering command: /usr/bin/wget wget --quiet --cache=off REDACTED -O /tmp/Rtmp8FaHDE/repos_http%3A%2F%2Fmirror.example.com%2Fcran%2Fsrc%2Fcontrib.rds (dns block)
    • Triggering command: /usr/bin/wget wget --quiet --cache=off REDACTED -O /tmp/Rtmp8FaHDE/file145673f2e278 .0-3build1.1_amd64.deb t ame (dns block)
    • Triggering command: /usr/bin/wget wget --quiet --cache=off REDACTED -O /tmp/Rtmp8FaHDE/file145673f2e278 (dns block)
  • packages.bioconductor.org
    • Triggering command: /usr/bin/wget wget --quiet --cache=off REDACTED -O /tmp/Rtmp8FaHDE/repos_http%3A%2F%2Fpackages.bioconductor.org%2Fpackages%2Fsrc%2Fcontrib.rds (dns block)
    • Triggering command: /usr/bin/wget wget --quiet --cache=off REDACTED -O /tmp/Rtmp8FaHDE/file14562167233b (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>catcall return object inserted directly in active document contextSee the snippet of code that was started below.</issue_title>
<issue_description>The purpose of cat call is to generate the actual code I want to copy and insert into the document. The update here calls for the function to directly insert it itself using the RStudio API R package (rstudioapi).

activeid <- rstudioapi::documentId(allowConsole = FALSE)          # active doc id
doc_path <- rstudioapi::documentPath(id = activeid)                   # active doc path
par_path <- fs::path_dir(doc_path)                                                # doc parent dir
pkg_path <- rprojroot::find_package_root_file(path = par_path) # package root (only if deving in a package)
pkg_name <- fs::path_file(pkg_path)                                            # package name (only if deving in a package)

</issue_description>

Comments on the Issue (you are @copilot in this section)


⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.

Copilot AI changed the title [WIP] Update catcall to insert object directly into active document context catcall: insert generated code directly into active RStudio document Mar 20, 2026
Copilot AI requested a review from bfatemi March 20, 2026 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

catcall return object inserted directly in active document contextSee the snippet of code that was started below.

2 participants