2

What does the "+" sign mean in RStudio? Most lines start with > but others start with + (for continue line I think). I'm reading along in a book and it is writing arguments for functions on separate lines but I'm not sure how to do that.

Or sometimes I see code like

> mtcars %>%
+   group_by(cyl) %>%
+   summarize(mean(mpg))
Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
amartino
  • 39
  • 1
  • 1
  • 4
  • 4
    It means you haven't finished the line yet. Missing brackets/parentheses. – Rich Scriven Sep 03 '14 at 05:37
  • possible duplicate of [Split code over multiple lines in an R script](http://stackoverflow.com/questions/6329962/split-code-over-multiple-lines-in-an-r-script) – Thomas Sep 14 '14 at 17:10

1 Answers1

6

As Richard Scriven stated, + is shown at the start of continuation lines. That is, when you pressed Enter without completing the R expression that you were typing. This is the case in all R IDEs (R GUI, Architect, etc.), not just RStudio.

The value that is printed is a global option: you can retrieve it using getOption("continue") and change it with the options function. I keep it set to spaces in order to make it easier to copy code from the command line to a script.

options(continue = "  ")

On Stack Overflow and other forums, most people will edit the posted code to remove the start-of-line characters (> on the first line of a command, + on additional lines for the same command). But sometimes you will encounter code without those symbols already removed - you will need to remove them yourself before copy/pasting the code into a script or your R console.

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360