How to do printf in r?

后端 未结 4 1559
青春惊慌失措
青春惊慌失措 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

    If you want a function that does print(sprintf(...)), define a function that does that.

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

提交回复
热议问题