Output in R, Avoid Writing “[1]”

后端 未结 4 718
独厮守ぢ
独厮守ぢ 2020-12-01 13:35

I use print to output from a function in R, for example:

print(\"blah blah blah\")

This outputs

[1] \"blah bla         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-01 14:13

    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
    

提交回复
热议问题