The question is so simple I can't seem to find an answer.
Use'SHIFT-ENTER' to get to a new line in R without executing the command.
Note for mac users: On mac is Ctrl + Enter
x <- c(1,2,3.5,4,5,6,7,8,9,10,11,12,13,14,15,
+ 16,17,18,19,20)
I did not write the “+” at the outset of the second line. If you hit the return key after the last comma on the first line, the plus sign will be produced by R as a new prompt and you can go on typing in the rest of the numbers.
If you are a mac user, try "Option + Enter", which works for me in R 4.1.2 (High Sierra).
Related
I have entered in code to plot a graph, but when I press Enter to execute the graph, it does not plot the graph. Rather, + symbols appear every time I press Enter to execute the command and plot the code.
Now there is a long column of + symbols in my R consoles.
Why is this happening and what can I do to prevent this from happening?
The prompt has + because it signifies that the prompt is expecting more from the line of code, a sort of continuation. This may be because you forgot to close something so the prompt expects the closing side. For example, say you forgot to close a string like so:
> "
+
+
Here, I entered a double-quote into the prompt and kept on pressing Enter. There is a missing double-quote to tell the prompt I've ended the string literal, so the prompt expects another double-quote. Once you enter the double quote the prompt will stop expecting it. For example:
> "
+
+ "
[1] "\n\n"
This is standard on all command prompts, to expect more code if something isn't ended properly, like the string literal above. Check your code to make sure you've closed all opening quotes, symbols, etc, so the prompt doesn't expect it and your code executes correctly.
The ways of exiting the prompt when this happens are:
Esc on RGui and RStudio
Ctrl-C on Terminals and Command Prompts
This could happen if you used space in the middle of an object name, eg. Column names. R doesn't allow space in between " ".
This question already has answers here:
ending "+" prompt in R
(5 answers)
Closed 6 years ago.
I'm new to R Programming and have somehow gotten stuck in an argument that will not stop. I wrote view(file) and hit enter and now there is an endless string of "+" and the argument will not close. Any help would be appreciated on how to close my argument. I know I can just force quit the program, but I would rather just figure out of to end the argument. Thank You!
In R, if you keep seeing an endless string of +, it means that you didn't close a pair of either single quotes '', double quotes "", or parentheses/brackets ()/{}.
Usually, not closing a pair of parentheses or brackets produces an error sooner or later. But open quotes can keep going forever if you do not close them (or unless you terminate the command: esc in RStudio or ctrl+c if in command line).
Here is an example:
> view("file
+ i can keep
+ writing
+ until
+ i close the
+ double quote
+ , but once I do,
+ I have to also close the parentheses )
+ "
+ )
Error: could not find function "view"
>
This question already has answers here:
TODO comments in rStudio
(4 answers)
Closed 5 years ago.
How do I use TO DOs in RStudio? By TO DOs I mean, some special flags or comments that would stand out, so I could get back to certain things I want to rework/modify etc.
I searched on Internet as well as on Rstudio, but I don't seem to be able to find such a functionality as other IDEs have (e.g. PyCharm when I code in python). I am using comments currently, but that is very imperfect in a bigger project that is heavily commented anyway.
Can you share your tips and tricks?
Ctrl + Shift + R to create a section label that stands out. Any code that sits between this and another section label can be minimized/maximized when you need to, and you can call it TO DO.
You can also use Alt + Shift + J to jump between these section labels when you want to rework or modify them.
The answer to this question might help, I suppose.
I am not sure if it is okay to copy the full text of that answer, so briefly:
Shift + Cmd + F / Shift + Ctrl + F
enter ^\s*# TODO:
^ means the start of the string we are interested in,
\s is for any whitespace character (space, tab, line break),
and the following * implies that the whitespace character is repeated zero to an infinite amount of times;
a-a-and – run the search!
I'm trying to select all of the results found by a regex find so I can modify them all (not replace them with text!), for example, making them all uppercase with Cmd + K -> Cmd + U. I'm aware that I could do them one by one via repeating Cmd + G, Cmd + K, Cmd + U, but for a large file this simply isn't practical or realistic. I'm also aware of using bash and may other scripting alternatives, I'd like to find a way to do it inside Atom, I'm happy to install an external library if needed.
Things I've tried:
Cmd + D, this just selects the next instance of that exact letter, not the next result matching the regex.
Cmd + Shift + G and alternatives (alt/right shift/ctrl), Cmd + G selects the next result matching the Regex, which is in the right direction.
Changing all of the selected text to a unique string, highlighting them all, pressing Cmd + Z and hoping it will stay selected, it doesn't.
Lots of Googling and reading though Atom discussions.
Reading Atom's documentation on the subject
Pressing Alt + Enter will select all instances matching your Find results. This works for RegEx search also.
Source: https://github.com/atom/find-and-replace/pull/290
On Atom 1.57 (nov 2021) clicking on "find all" selects all matching items, esc to exit the search box, then copy :)
Alternatively you can select all whit the menu -> find > select all.
On mac also selects all by pressing ^ + cmd + G.
A similar question was asked a year ago, but the requirements were different (querent wanted R studio), and the solution package is not compatible with R 3.0.
I am using the R interpreter directly from the bash command line. I would like my scripts to output color text, ideally in a manner similar to how using a particular sequence of characters in C causes the color to be different.
More specifically, in C, we can output colors using printf as described in the answer to this question. I wonder if R 3.0.2 has a facility to do the same.
The ANSI sequences in the question you mentioned are processed by the terminal emulator so they will work fine in R:
cat("\033[32;1m OK \033[0m\n")
Note that \033 is (octal) code for escape symbol. It is one (non-printable) symbol which tells the terminal to start interpreting the control sequence. print when given \033 will output the four symbols \, 0, 3, 3 literally which, of course, tells the terminal nothing. See Wikipedia for the full list of ANSI escape sequences.