in R, can I stop print(cat(“”)) from returning NULL? and why does cat(“foo”) return foo>

后端 未结 6 1370
北恋
北恋 2021-02-18 19:48

If I enter

print(cat(\"\"))

I get

NULL

I want to use cat() to print out the progress of an R sc

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-18 20:10

    All your answers are in the documentation for ?cat. The portions that answer your specific question are:

    Arguments:

    fill: a logical or (positive) numeric controlling how the output is
          broken into successive lines.  If ‘FALSE’ (default), only
          newlines created explicitly by ‘"\n"’ are printed.
          Otherwise, the output is broken into lines with print width
          equal to the option ‘width’ if ‘fill’ is ‘TRUE’, or the value
          of ‘fill’ if this is numeric.  Non-positive ‘fill’ values
          are ignored, with a warning.
    

    ... and ...

    Value:

     None (invisible ‘NULL’).
    

    So you can't stop print(cat(...)) from returning NULL because that's what cat returns. And you need to explicitly add newlines like cat("foo\n").

提交回复
热议问题