I use print
to output from a function in R, for example:
print("blah blah blah")
This outputs
[1] "blah blah blah"
To the console. How can I avoid the [1]
and the quotes?
It means that [1] represents the first value returned by the function called? – Shaun. Jun 2, 2015 at 11:48. yes it is indicating that only try list(s=c(1:2),b=c(2:5)) you will get two [1] since two vectors are being printed.
The shortcut to interrupt a running process in R depends on the R software and the operating system you are using. However, if you are using RStudio on a Windows computer, you can usually use Esc to stop a currently executing R script. Then, we can press Esc to interrupt the loop.
Most common method to print output in R program, there is a function called print() is used. Also if the program of R is written over the console line by line then the output is printed normally, no need to use any function for print that output. To do this just select the output variable and press run button.
Use cat("Your string")
(type ?cat
to see help page) to output concatenated objects to standard output.
message
is probably the best function to replace print
for your needs. cat
is also a good function to look at but message
will print a new line for you as well. It is also better to use since it is easier to suppress the output from message
than it is to suppress the output from cat
.
If you just want to remove the quotes but don't mind the [1] printing then you could use the quote=FALSE
option of print
.
Edit: As noted in the comments, message
isn't the same as a call to print
as it sends the output to a different connection. Using cat
will do what you want as others have noted but you'll probably want to add a new line on after your message.
Example
cat("This is a message\n") # You'll want to add \n at the end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With