Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shrtcts executing multiple shortcuts when only one is called #24

Closed
danswart opened this issue Aug 7, 2023 · 5 comments
Closed

shrtcts executing multiple shortcuts when only one is called #24

danswart opened this issue Aug 7, 2023 · 5 comments

Comments

@danswart
Copy link

danswart commented Aug 7, 2023

My apologies; I don't even know if this is a 'bug'. Newbie barely describes my skill level!

When I call a shrtcts (either from the Addins menu, or from a hotkey assigned in RStudio IDE), ALL shortcuts whose execution code uses rstudioapi::insertText() run until they have all run. They even write the specified text in the r chunk when I execute shrtcts::add_rstudio_shortcuts() to rewrite the .shrtcts.R file in the config folder in the home directory. If I add any other shrtcts using rstudioapi::insertText() it just runs that right along with the previous shrtcts. I'm sure I don't understand that function well. It all works for me as you designed it except this one item. I do not use the hotkey assignment feature built in to shrtcts.

Here's the code in the .shrtcts.R file:

#' SlideInRight
#'
#' SlideInRight
#'
#'@id 1
#'@interactive
#'
sir <- "slideInRight slideOutRight"
rstudioapi::insertText(sir)

#' SlideInTop
#'
#' SlideInTop
#'
#'@id 2
#'@interactive
#'
sit <- "slideInTop slideOutTop"
rstudioapi::insertText(sit)

Thank you. Dan Swart

@gadenbuie
Copy link
Owner

gadenbuie commented Aug 7, 2023

Hi @danswartcpa! Fortunately, the fix is pretty easy. Each shortcut needs to be encapsulated in a function. The doesn't need to be a named, but it helps and I recommend it:

#' SlideInRight
#'
#' SlideInRight
#'
#' @id 1
#' @interactive
#'
slide_in_right <- function() {
  sir <- "slideInRight slideOutRight"
  rstudioapi::insertText(sir)
}

#' SlideInTop
#'
#' SlideInTop
#'
#' @id 2
#' @interactive
#'
slide_in_top <- function() {
  sit <- "slideInTop slideOutTop"
  rstudioapi::insertText(sit)
}

@danswart
Copy link
Author

danswart commented Aug 7, 2023

God bless you, Garrick. You are my hero!

I go to you first for all my r needs.

I know your documentation states that all shrtcts need to be made as a function, but when I saw some of your examples, like for restarting an R session, it appeared that the executable was a strait function call with arguments. I'm too inexperienced to understand what that meant.

On YT I've heard you say...I've spent an embarrassing amount of time on this...! Me too on this one. You really put me back on track here. Thank you.

Dan Swart

@gadenbuie
Copy link
Owner

Awesome, glad that worked and today you learned something new! By the way, if you want a little more inspiration, I just remembered that I added example shrtcts files. Try shrtcts::example_shortcuts_r(), which prints out a "starter" shortcuts R script that you can use.

@danswart
Copy link
Author

danswart commented Aug 7, 2023 via email

@atsyplenkov
Copy link

Fortunately, the fix is pretty easy. Each shortcut needs to be encapsulated in a function. The doesn't need to be a named, but it helps and I recommend it:

Hey, @gadenbuie 👋
Maybe you can add this into the README file or in the Get Started section? I have also encountered this issue. Unfortunately, it's not really straightforward from the package documentation that it's better to wrap all shortcuts in functions :(

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

No branches or pull requests

3 participants