terminal_close_linter | R Documentation |
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.
terminal_close_linter()
best_practices, robustness
linters for a complete list of linters available in lintr.
# 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()
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.