slipleft
slipleft

Reputation: 385

wrap code in R Studio text editor

How can one wrap commands within a lengthy line of code in the text editor in RStudio such that RStudio recognizes it as the continuation of a single piece of code? Currently, my code is 1 incredibly long line that is difficult to manage. With my current RStudio configuration, "Enter" seems to establish a new and separate line of code (without an indent) that RStudio doesn't process correctly because it begins with a "+".

Soft wrap (auto wrap based upon width of the text editor window) is not what I'm looking for.

Example what what I'm trying to achieve:

ggplot(C, aes(x=Tenure, y = Count, color=Gender, shape=Gender))
     + geom_point(size=1)
     + geom_smooth(aes(fill=Gender))
     + labs(x="Tenure", y="Closeness")
     + ggtitle("Title")

Shift + Enter and Control + Enter are not doing the trick.

Upvotes: 36

Views: 66436

Answers (1)

user9695427
user9695427

Reputation:

"4. Enable code wrapping If, like me, you like to work with multiple windows up at once, you will undoubtedly run into the issue of not being able to see your code without scrolling sideways. While the best solution is to simply get in the habit of chopping your code up into shorter, more legible segment, a fair alternative is to have R Studio “soft wrap” it for you. All this means is that any part of your R script that would usually fall off the side of your screen is, instead, continued on the following line. Give it a try:"

enter image description here

Upvotes: 70

Related Questions