Debian Codegraph @

man/with_connection.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/connection.R
3 \name{with_connection}
4 \alias{with_connection}
5 \alias{local_connection}
6 \title{Connections which close themselves}
7 \usage{
8 with_connection(con, code)
9
10 local_connection(con, .local_envir = parent.frame())
11 }
12 \arguments{
13 \item{con}{For \code{with_connection()} a named list with the connection(s) to
14 create. For \code{local_connection()} the code to create a single connection,
15 which is then returned.}
16
17 \item{code}{\code{[any]}\cr Code to execute in the temporary environment}
18
19 \item{.local_envir}{\verb{[environment]}\cr The environment to use for scoping.}
20 }
21 \value{
22 \code{[any]}\cr The results of the evaluation of the \code{code}
23 argument.
24 }
25 \description{
26 R file connections which are automatically closed.
27 }
28 \examples{
29 with_connection(list(con = file("foo", "w")), {
30 writeLines(c("foo", "bar"), con)
31 })
32
33 read_foo <- function() {
34 readLines(local_connection(file("foo", "r")))
35 }
36 read_foo()
37
38 unlink("foo")
39 }
40 \seealso{
41 \code{\link{withr}} for examples
42 }