Introduction
Providing output to the screen is an important part of any program. In this lesson we will review the most common techniques for printing to the console and knitted HTML documents. This lesson does not cover how to output results to a user interface or the web. For this you need to use packages such as tcltk or shiny.
Outputting values to the console is also important for ad hoc debugging.
There are several functions that are commonly used to output results to the console:
print()
, often combined with paste()
head()
and tail()
for dataframes and vectors
sprintf()
cat()
message()
knitr::raw_html()
To add HTML to the knitted document, we often use knitr::raw_html()
.
Let’s take a look at each of the functions and their most common use cases. We will start with the most commonly used function for printing to the console: print()
.
print()
print()
is the most commonly used function for printing messages and the value of R objects and variables to the console. In its simplest form, just using a variable as a stand-along statement prints its contents. Alternatively, calling print()
with a single argument will print the variable. Calling print()
is preferable as it makes the intent of printing the variables clear. As an aside, be careful printing large dataframes or vectors. For that use the head()
function instead.
x <- 23.77
# display the contents of the variable
x
## [1] 23.77
# display contents using print()
print(x)
## [1] 23.77
For more complex output or to output several variables, a single argument has to be formed using the paste()
function. The paste()
function is the R way to concatenate strings.
x <- 23.77
# display the contents of the variable
x
## [1] 23.77
# display contents with surrounding text
print(paste("x =", x))
## [1] "x = 23.77"
paste() and paste0()
The paste()
function is used to concatenate (combine) strings. By default, the arguments are separated by a space. To separate the strings with any other string, use the argument sep. To get rid of any separator, either use sep=““ or the paste0()
function which sets sep=““ by default but otherwise works like paste()
. The code below illustrates the various parameters.
x <- 100.99
s <- paste("The result is", x)
print(s)
FALSE [1] "The result is 100.99"
print(paste("Amount: ", "$", x, sep=""))
FALSE [1] "Amount: $100.99"
print(paste0("Amount: ", "R$", round((x/5.14),2)))
FALSE [1] "Amount: R$19.65"
head() and tail()
The head()
function is the preferred way to display a subset of a dataframe or a vector. The function takes an optional argument that determines how many rows will be printed; the default is 6. The tail()
function is the same as head()
except that it prints at rows at the end rather than beginning (from the tail rather than the head of the structure).
df <- read.csv("customertxndata.csv")
head(df, 3)
## NumVisits NumOrders OS Gender Total
## 1 7 0 Android Male 0.0000
## 2 20 1 iOS <NA> 576.8668
## 3 22 1 iOS Female 850.0000
## NumVisits NumOrders OS Gender Total
## 22799 1 0 Android Male 0
## 22800 13 1 Android Male 340
cat()
Notice that it still prints the result as a vector with the element number, e.g., above it printed [1] before. This can be eliminated by using cat()
rather than print()
.
100.99
Unlike print()
, cat()
takes a variable number of argument, so the need for paste()
is not as common.
x = 100.99
Rather than printing the contents to the console (or as part of a knitted document), cat()
can also direct the output to a file using the argument file. This is particularly useful for log messages in R Scripts. Use the argument append=T to append subsequent outputs to the same file. Also, by default, subsequent output is to the same line, unless the argument fill=T is specified or the separator is set to a newline character with sep=““. The code below illustrates these features.
cat('x =', x, file = "log.txt", append = T, sep="\n")
Notice that by default the arguments are separated by a space, although the argument sep can modify that to a newline or another separator character such as “,” for CSV files.
sprintf()
The sprintf()
function provides output formatting similar to the function with the same name in C. The result is “output” to a string which can then be echoed to the console using either print()
or cat()
.
The format string options are the same as in C.
x <- 87.34
c <- "R$"
s <- sprintf("The amount is %s%f", c, x)
print(s)
## [1] "The amount is R$87.340000"
The first argument is the format string which contains text plus formatting options. The remaining arguments are added to the first argument in place of the formatting options. So, in the example above, the value of c is added where %s appear while the value of x is added to where %f appears. The value is formatted according to the format, e.g., %s is for strings and %f is for floating point numbers. Other formats include %e for scientific notation, %d for integers, among others. The code below illustrates this with examples. Note the format specification for floating point numbers.
x <- 97.958 # floating point number
i <- 1024 # integer
s <- 'brown cow' # string/text
print(
sprintf("%d / %.2f / %s", i, x, s)
)
## [1] "1024 / 97.96 / brown cow"
message()
The output of the message()
function within an R code block (code fence) can be suppressed with the argument message = F.
In the block below, the argument the message argument is TRUE, so messages are displayed.
```{r message=T}
...
```
x <- 12.77
message("debug info / x = ", x)
## debug info / x = 12.77
On the other hand, in the block below, the argument is now set to FALSE, so output from the message()
is suppressed. This can be useful for debug message that can be turned off for a block or the entire document with the knitr::opt_chunks()
function.
x <- 12.77
message("debug info / x = ", x)
Notice that there is no message being printed.
knitr::raw_html()
This function only applies when knitting a document to HTML, although there are similar functions for LaTeX and PDF output formats. Recall that knitting a document produces an HTML file. Using knit::raw_html()
one can add any arbitrary HTML sequence to the result document at the location in the document where the function is called.
knitr::raw_html("<pre>Random <b>HTML</b>.</pre>")
Random HTML.
This can be particularly useful for special formatting, computed HTML, or special characters.
Summary
R provides several ways to display results on the console. The most common functions are print with paste0 and cat, while debug and other information messages are displayed using messag_e. For injecting HTML we generally use knitr::raw_html. The sprintf function can be useful for producing formatted strings.
Errata
None collected yet. Let us know.
LS0tDQp0aXRsZTogIkNvbnNvbGUgT3V0cHV0IGluIFIiDQpwYXJhbXM6DQogIGNhdGVnb3J5OiA2DQogIG51bWJlcjogMTkwDQogIHRpbWU6IDIwDQogIGxldmVsOiBiZWdpbm5lcg0KICB0YWdzOiAicixjb25zb2xlLG1lc3NhZ2Usc3ByaW50ZixwcmludCxwYXN0ZSxjYXQiDQogIGRlc2NyaXB0aW9uOiAiSWxsdXN0cmF0ZXMgZGlmZmVyZW50IGZ1bmN0aW9ucyBpbiBSIGZvciBwZXJmb3JtaW5nDQogICAgICAgICAgICAgICAgY29uc29sZSBvdXRwdXQsIGluY2x1ZGluZyBwcmludCgpLCBjYXQoKSwgcHJpbnRmKCksDQogICAgICAgICAgICAgICAgc3ByaW5nZigpLCBhbmQgbWVzc2FnZSgpLiBQcm92aWRlcyB1c2UgY2FzZXMgZm9yIGVhY2ggYW5kDQogICAgICAgICAgICAgICAgd2hlbiB0byBiZXN0IHVzZSB0aGVtLiINCmRhdGU6ICI8c21hbGw+YHIgU3lzLkRhdGUoKWA8L3NtYWxsPiINCmF1dGhvcjogIjxzbWFsbD5NYXJ0aW4gU2NoZWRsYmF1ZXI8L3NtYWxsPiINCmVtYWlsOiAibS5zY2hlZGxiYXVlckBuZXUuZWR1Ig0KYWZmaWxpdGF0aW9uOiAiTm9ydGhlYXN0ZXJuIFVuaXZlcnNpdHkiDQpvdXRwdXQ6IA0KICBib29rZG93bjo6aHRtbF9kb2N1bWVudDI6DQogICAgdG9jOiB0cnVlDQogICAgdG9jX2Zsb2F0OiB0cnVlDQ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3IgY29kZT14ZnVuOjpyZWFkX3V0ZjgocGFzdGUwKGhlcmU6OmhlcmUoKSwnL1IvX2RlcGxveUtuaXQuUicpKSwgaW5jbHVkZSA9IEZBTFNFfQ0KYGBgDQo=
Comment Option for Code Blocks
Note that the output within an R Notebook code block (or code fence) display the ## prefix. Ti illustrate look at the output of the code block below.
To suppress the printing of the prefix, use the code block option:
The result is shown below. Of course, you can specify any other string as a prefix.