0

this might be nastily easy to answer:

How do I execute folded coded and in particular functions, for-loops, and alike in RStudio?

I have perused the documentary pages twice. nada.

EDIT: But that doesn't work: If I execute the assign of a function:

ff <- function(x) {x+1 return(x)} 

I get this return in non-folded manner: strg+enter

ff <- function(x) {x+1 + return(x)}

and this when I execute the folded lines by strg+enter

> return(x)}
> Error: unexpected '}' in "return(x)}"+ return(x)}
IRTFM
  • 258,963
  • 21
  • 364
  • 487
Toby
  • 533
  • 4
  • 15
  • 3
    How do you execute non-folded code? You select the code, then press [CTRL+ENTER]. Do the same with folded code. – Andrie Jul 05 '13 at 12:05
  • I got it: You have to select the line with the folded code so that the cursor is on the next line at the very first position. If you execute then, it works. i.e. it does not work, if you have the cursor at the end of the line of the folded part. – Toby Jul 05 '13 at 14:48

2 Answers2

1

You want to add a ; between expressions:

ff <- function(x) {x+1; return(x)} 

Btw, my answer has nothing to do with RStudio, it rather answers:

How do you execute multiple statements per code block enclosed by {} when the statements are in one line?

Henrik
  • 14,202
  • 10
  • 68
  • 91
0

Only an extended comment: I'm guessing there is potential German-English confusion here. In English the three "special keys" on a Windows keyboard are "control" , "alt", and "windows", whereas on a Mac keyboard they "control", option", and "command". Originally I thought you might mean 'string+enter' or 'alt+enter' but on the basis of googling "strg+enter keyboard German" I'm thinking you mean "control-enter".

After scrolling through the keyboard shortcuts in the RStudio documentation, I'm wondering if rather than 'ctrl-enter', you really want 'windows+enter', although you will still need the semicolon, if those characters are all on the same line, or whatever it might be called in German.

IRTFM
  • 258,963
  • 21
  • 364
  • 487