--4-Advanced inputs and outputs
# Pass the readLines() function to safely(), and assign the output to safe_readLines.
# Use safe_readLines() on the string "http://example.org" to read
# the example homepage HTML file.
# Use safe_readLines() on "http://asdfasdasdkfjlda", a nonsense web address that
# shouldn't be found
install.packages("purrr")
library(purrr)
readLines<-function (con = stdin(), n = -1L, ok = TRUE, warn = TRUE,
encoding = "unknown",
skipNul = FALSE)
{
if (is.character(con)) {
con <- file(con, "r")
on.exit(close(con))
}
.Internal(readLines(con, n, ok, warn, encoding, skipNul))
}
# Create safe_readLines() by passing readLines() to safely()
safe_readLines <- safely(readLines)
safe_readLines
# Call safe_readLines() on "http://example.org"
safe_readLines("http://example.org")
safe_readLines
# Call safe_readLines() on "http://asdfasdasdkfjlda"
safe_readLines("http://asdfasdasdkfjlda")
safe_readLinesLast updated