How to do printf in r?

后端 未结 4 1566
青春惊慌失措
青春惊慌失措 2020-12-15 15:24

I\'m looking for how to do printf in r, ie I want to type:

printf(\"hello %d\\n\", 56 )

and get the same output as typing:

         


        
4条回答
  •  情深已故
    2020-12-15 15:45

    My solution:

    > printf <- function(...) cat(sprintf(...))
    > printf("hello %d\n", 56)
    hello 56
    

    The answers given by Zack and mnel print the carriage return symbol as a literal. Not cool.

    > printf <- function(...) invisible(print(sprintf(...)))
    > printf("hello %d\n", 56)
    [1] "hello 56\n"
    > 
    > printf <- function(...)print(sprintf(...))
    > printf("hello %d\n", 56)
    [1] "hello 56\n"
    

提交回复
热议问题