Reputation: 1522
Is there a shortcut to add a new line into the R (RStudio) code?
I would like to avoid something like gapminder%>%filter(continent=="Asia")%>%group_by(year)%>%summarise(mean_pop=mean(pop))%>%ggplot(aes(x=year,y=mean_pop))+geom_point()+geom_line()+theme_bw()
by using
gapminder %>%
filter(continent == "Asia") %>%
group_by(year) %>%
summarise(mean_pop = mean(pop)) %>%
ggplot(aes(x = year, y = mean_pop)) +
geom_point() +
geom_line() +
theme_bw()
but without holding the space bar all the time.. and I googled now nearly half an hour and just didn't find a shortcut. Can't believe it?! So how all are doing this?
Upvotes: 1
Views: 201
Reputation: 545618
RStudio has separate windows for editing code and executing commands:
In this case, the top left is the code editor (but the layout is modifiable). Below is the console.
To edit code, create a new file or open an existing file, and edit it in the code editor. RStudio will automatically attempt to format your code as appropriate when you hit Return.
To execute code you’ve written in the code editor there are several choices. To execute just the current statement, you can hit Cmd+Return. There are more options directly above the code editor (check out the menus ‹Run› and ‹Source›).
Upvotes: 2
Reputation: 33147
In your case try to use ;
and not %>%
.
Example:
gapminder;filter(continent=="Asia");group_by(year);summarise(mean_pop=mean(pop))
Press CTRL + SHIFT + A or select all code and go to Code-> Reformat code
Result:
gapminder
filter(continent == "Asia")
group_by(year)
summarise(mean_pop = mean(pop))
Upvotes: 0