How do I run a function definition from inside it?

I write functions with many lines of code. While I am writing these functions I make frequent changes. To test a function I scroll to the bottom of the function, click just after the closing "}" and hit CTRL+ENTER. That works fine but much is time wasted scrolling up and down. Is there a command in RStudio that would run the definition of the function the cursor is in?

Ctrl + Alt + F should run the current function definition at your cursor's location.

You can see more Rstudio shortcuts with Alt + Shift + K, or using the Tools -> Keyboard Shortcuts Help menu. I found this one under the "Execute" header.

1 Like

Thanks, but I don't want to run a function. I want to run a function definition. Something like myfunction <- function(x) { many lines of code }. I am in the middle of those many lines of code and do not want to scroll to the bottom and click just after "}" and hit CTRL+ENTER. I would like to run the definition from where I am in the middle of the body of the function.

That's exactly what Ctrl + Alt + F does. Did you even bother to try it?

Hello Soldalma, to search about desk shortcuts, you can see the documentation, or just search in your keyboard.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.