├── .Rbuildignore ├── .gitignore ├── tools └── dash.png ├── NAMESPACE ├── inst └── rstudio │ └── addins.dcf ├── dash.Rproj ├── DESCRIPTION ├── R └── runSelectionAsJob.R └── README.md /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^dash\.Rproj$ 2 | ^\.Rproj\.user$ 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | -------------------------------------------------------------------------------- /tools/dash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jonocarroll/dash/HEAD/tools/dash.png -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: fake comment so roxygen2 overwrites silently. 2 | exportPattern("^[^\\.]") 3 | -------------------------------------------------------------------------------- /inst/rstudio/addins.dcf: -------------------------------------------------------------------------------- 1 | Name: Run as Job in Background 2 | Description: Runs the selection as a background Job. 3 | Binding: runSelectionAsJob 4 | Interactive: false 5 | -------------------------------------------------------------------------------- /dash.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageRoxygenize: rd,collate,namespace 22 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: dash 2 | Version: 0.0.1 3 | Title: RStudio Addin to Run a Selection as a Background Job 4 | Description: Jumping the gun to utilise RStudio Jobs. This will likely 5 | be implemented properly later, but I'm impatient and wanted to play. 6 | Authors@R: person("Jonathan", "Carroll", 7 | email = "rpkg@jcarroll.com.au", 8 | role = c("aut", "cre"), 9 | comment = c(ORCID = "0000-0002-1404-5264")) 10 | Maintainer: Jonathan Carroll 11 | License: WGPL (>=3) 12 | Encoding: UTF-8 13 | LazyData: true 14 | ByteCompile: true 15 | -------------------------------------------------------------------------------- /R/runSelectionAsJob.R: -------------------------------------------------------------------------------- 1 | runSelectionAsJob <- function() { 2 | 3 | ## Get the document context. 4 | context <- rstudioapi::getActiveDocumentContext()$selection[[1]]$text 5 | 6 | ## if not empty selection 7 | if (!is.null(context) && context != "") { 8 | 9 | ## save selection to a temporary file 10 | tf <- tempfile("dashJob", fileext = ".R") 11 | writeLines(context, con = tf, sep = "\n") 12 | 13 | ## run the temp script as a job, returning the 14 | ## results to the global environment 15 | .rs.api.runScriptJob( 16 | path = path.expand(tf), 17 | importEnv = TRUE, 18 | workingDir = getwd(), 19 | exportEnv = "R_GlobalEnv" 20 | ) 21 | 22 | } 23 | 24 | ## delete temporary file 25 | on.exit({ 26 | ## allow time for scripting to start 27 | Sys.sleep(5) 28 | unlink(tf) 29 | }) 30 | 31 | } 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dash 2 | 3 | RStudio Addin to Run a Selection as a Background Job 4 | 5 | ![](./tools/dash.png) 6 | 7 | RStudio daily release now includes a Jobs pane. See this excellent demo from @hrbrmstr for details. 8 | 9 | RStudio Jobs 12 | 13 | This allows one to source a script as a background job. But what about incidental code? This Addin allows one to highlight a region of code to be run as a background job. 14 | 15 | ## Installation 16 | 17 | You can install the development version of `dash` from GitHub or GitLab 18 | 19 | ``` r 20 | devtools::install_github("jonocarroll/dash") 21 | devtools::install_gitlab("jonocarroll/dash") 22 | ``` 23 | 24 | ## NOTES 25 | 26 | * `dash` hastily pre-empts any official implementation, and as such will be rendered useless once that is complete. 27 | * `dash` has been tested with RStudio 1.2.719. The API is under constant development and as such this could break at any daily release. I will try to keep up as best as I can. The internals became available as PR #2923 was merged, which means the earliest daily this should be compatible with is probably 28 | 29 | | Filename | Published | Commit | Build ID | 30 | |:-----|:-----|:-----|:-----| 31 | | rstudio-1.2.712-amd64.deb | 2018-06-08 20:22:28 | 87458be9 | da7b43c700e714272546b76297fc64a8-12 | 32 | 33 | * There doesn't appear to be an exported way to STOP a job, so keep an eye on your infinite loops. 34 | * `dash` writes the selection as a temporary file and sources that, so the selected code must be valid. 35 | * Obviously requires a fairly recent version of RStudio. 36 | * `install_gitlab` requires the development version of `r-lib/devtools`. 37 | --------------------------------------------------------------------------------