Skip to content

Commit

Permalink
Call 'rstudioapi' to set focus is R console
Browse files Browse the repository at this point in the history
This has been bothering me for a long time. Finally found a way of transferring the focus to the console from a script in the editor pane!! Needs testing that it not causes difficulties when the functions are run at the console instead of through a script.
  • Loading branch information
aphalo committed May 29, 2023
1 parent f377818 commit ebd3bb9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: ooacquire
Type: Package
Title: Acquire Data from OO Spectrometers
Version: 0.3.4.9000
Date: 2023-05-26
Date: 2023-05-30
Authors@R:
c(
person("Pedro J.", "Aphalo", email = "pedro.aphalo@helsinki.fi", role = c("aut", "trl", "cre")),
Expand Down Expand Up @@ -40,6 +40,7 @@ Imports:
magrittr (>= 2.0.3)
Suggests:
rOmniDriver (>= 0.1.19),
rstudioapi (>= 0.10),
knitr (>= 1.39),
rmarkdown (>= 2.14),
testthat (>= 3.1.4)
Expand Down
6 changes: 6 additions & 0 deletions R/acq-fraction-interactive.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ acq_fraction_interactive <-

w <- start_session()

# Transfer focus to console (e.g., from editor pane)
if (requireNamespace("rstudioapi", quietly = TRUE) &&
rstudioapi::isAvailable()) {
rstudioapi::executeCommand('activateConsole')
}

instruments <- list_srs_interactive(w = w)
sr.index <- choose_sr_interactive(instruments = instruments)
if (sr.index < 0L) {
Expand Down
6 changes: 6 additions & 0 deletions R/acq-irrad-interactive.R
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ acq_irrad_interactive <-
w <- start_session()
on.exit(end_session(w)) # ensure session is always closed!

# Transfer focus to console (e.g., from editor pane)
if (requireNamespace("rstudioapi", quietly = TRUE) &&
rstudioapi::isAvailable()) {
rstudioapi::executeCommand('activateConsole')
}

instruments <- list_srs_interactive(w = w)
sr.index <- choose_sr_interactive(instruments = instruments)
if (sr.index < 0L) {
Expand Down
Binary file modified src/ooacquire.dll
Binary file not shown.

0 comments on commit ebd3bb9

Please sign in to comment.