ENH: Have the ability to run a script
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
Begin with related rstudioapi issue #112 and the terminalSend, terminalCreate, terminalActivate, and documentNew calls shown here. Clarify whether automated execution must keep plots and output in RStudio's Console or Viewer rather than external terminal devices, then define an acceptance test for that behavior.
Written by the indexing model from the issue text.
Description
Description of the problem
@kasperdanielhansen
May be related in some small way to https://github.com/rstudio/rstudioapi/issues/112.
The goal is to be able to have a set of R commands that you either a) create with the script or b) already have, and have that execute in order to show how the output would look in RStudio. The goal is to create a way to essentially run the commands as you would live, but in an automated way
Current attempt
One of the issues if you're running commands from a source editor to insert text in another editor, you have to be careful about which editor ID you're using. Moreover, using this solution is not appealing as you have the script command to generate the text inside the editor showing up in the console.
The idea then was to try this with the Terminal:
library(rstudioapi)
execution = function(code,
location = Inf,
term_id = NULL,
id = NULL, time = 1,
add_newline = TRUE) {
if (add_newline) {
code = paste0(code, "\n")
}
insertText(
location,
text = code,
id = id)
Sys.sleep(time)
terminalActivate()
rstudioapi::terminalSend(text = code, id = term_id)
setCursorPosition(
position = Inf,
id = id)
Sys.sleep(time)
}
# create new document
documentNew("# we will write here\n", type = "r",
position = document_position(0, 0))
# wait for it to open
Sys.sleep(1)
# get the id
document = getSourceEditorContext()
id = document$id
setCursorPosition(
position = Inf,
id = id)
Sys.sleep(1)
# open up a terminal
term_id = terminalCreate()
terminalActivate()
terminalClear(term_id)
# Run R
terminalSend(id = term_id, "R\n")
terminalActivate()
# execute the commands in Terminal while pasting in editor
execution("# Hello", id = id, term_id = term_id)
execution("x = 5", id = id, term_id = term_id)
execution("y = 4", id = id, term_id = term_id)
execution("x + y", id = id, term_id = term_id)
# wait until execution reasonably done
Sys.sleep(10)
# kill R
terminalSend(id = term_id, "q('no')\n")
# kill the terminal
sapply(terminalList(), terminalKill)
Issues with Current Attempt
The issue is that any plots and output is not really in the Console/RStudio Viewer but external image panes/devices (such as Quartz devs) as it's done from the terminal. If you try it in reverse, it doesn't work as the Terminal R doesn't inherit the RStudio functionality.
Would this be possible to do via webshot and an RStudio server session maybe? @wch
- Dominant language
- R
- Stars
- 175
- Forks
- 37
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rstudio/rstudioapi
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
rstudio/rstudioapi#313 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 48/100
rstudio/rstudioapi#321 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
rstudio/rstudioapi#318 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
rstudio/rstudioapi#315 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
rstudio/rstudioapi#314 ·
All issues in rstudio/rstudioapi
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
r-lib/pkgdepends#485 · 3 comments ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
beginners blocker
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enviPathR OpenBuild Error Build OK Build Warning policies-accepted pre-review precheck-passed
Difficulty 1/5 Under an hour Newbie friendliness 84/100
Bioconductor/BiocContributions#207 · 6 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
datacarpentry/semester-biology#1255 ·