terminal_close_linter {lintr} | R Documentation |
Prohibit close() from terminating a function definition
Description
Functions that end in close(x)
are almost always better written by using
on.exit(close(x))
close to where x
is defined and/or opened.
Usage
terminal_close_linter()
Tags
See Also
linters for a complete list of linters available in lintr.
Examples
# will produce lints
code <- paste(
"f <- function(fl) {",
" conn <- file(fl, open = 'r')",
" readLines(conn)",
" close(conn)",
"}",
sep = "\n"
)
writeLines(code)
lint(
text = code,
linters = terminal_close_linter()
)
# okay
code <- paste(
"f <- function(fl) {",
" conn <- file(fl, open = 'r')",
" on.exit(close(conn))",
" readLines(conn)",
"}",
sep = "\n"
)
writeLines(code)
lint(
text = code,
linters = terminal_close_linter()
)
[Package lintr version 3.2.0 Index]