Reputation: 353
I am learning how to use short cuts in Rstudio in order to speed up writing R codes.
ctrl+alt+f is explained as "Runs current function definition" in the short cut list.
First, I do not understand how to specify "current" function. Second, I tried to use this short cut but nothing happened. I first defined a function in one R file and used function to calculate. Then, I selected the function identifier when the function was used to calculate. I used PC and pressed the short cut, then did not see any effect.
Upvotes: 1
Views: 343
Reputation: 625
What this means is, if you're in the scripting window in RStudio, and your cursor is in the middle of a function definition, then pressing Ctrl+Alt+F automatically figures out the lines where the function is written and passes that to the console. For example, if you had
myfn <- function(x, thresh){
x <- sort(x)
y <- ifelse(x < thresh, x^2, 2*x)
plot(x,y, type='l')
}
then, if your cursor was on the line x <- sort(x)
and you pressed Ctrl+Alt+F, the entire function definition, from myfn <- ...
to the final }
would be sent to the R console. This functionality allows you to send functions to R without having to select and then send, or copy and paste. Hope this helps.
Upvotes: 3