R file connections which are automatically closed.
with_connection(con, code)local_connection(con, .local_envir = parent.frame())
local_connection(con, .local_envir = parent.frame())
[any] The results of the evaluation of the code
[any]
code
argument.
For with_connection() a named list with the connection(s) to create. For local_connection() the code to create a single connection, which is then returned.
with_connection()
local_connection()
[any] Code to execute in the temporary environment
[environment] The environment to use for scoping.
[environment]
withr for examples
withr
with_connection(list(con = file("foo", "w")), { writeLines(c("foo", "bar"), con) }) read_foo <- function() { readLines(local_connection(file("foo", "r"))) } read_foo() unlink("foo")
Run the code above in your browser using DataLab