Learn R Programming

logr (version 1.0.3)

log_print: Print an object to the log

Description

The log_print function prints an object to the currently opened log.

Usage

log_print(x, ..., console = TRUE, blank_after = TRUE, msg = FALSE)

Arguments

x

The object to print.

...

Any parameters to pass to the print function.

console

Whether or not to print to the console. Valid values are TRUE and FALSE. Default is TRUE.

blank_after

Whether or not to print a blank line following the printed object. The blank line helps readability of the log. Valid values are TRUE and FALSE. Default is TRUE.

msg

Whether to print the object to the msg log. This parameter is intended to be used internally. Value values are TRUE and FALSE. The default value is FALSE.

Value

The object, invisibly

Details

The log is initialized with log_open. Once the log is open, objects like variables and data frames can be printed to the log to monitor execution of your script. If working interactively, the function will print both to the log and to the console. The log_print function is useful when writing and debugging batch scripts, and in situations where some record of a scripts' execution is required.

If requested in the log_open function, log_print will print a note after each call. The note will contain a date-time stamp and elapsed time since the last call to log_print. When printing a data frame, the log_print function will also print the number and rows and column in the data frame. These counts may also be useful in debugging.

See Also

log_open to open the log, and log_close to close the log.

Examples

Run this code
# NOT RUN {
# Create temp file location
tmp <- file.path(tempdir(), "test.log")

# Open log
lf <- log_open(tmp)

# Send message to log
log_print("High Mileage Cars Subset")

# Perform operations
hmc <- subset(mtcars, mtcars$mpg > 20)

# Print data to log
log_print(hmc)

# Close log
log_close()

# View results
writeLines(readLines(lf))
# }

Run the code above in your browser using DataLab