Skip to contents

mode = "w" (the default) or mode = "a" in download.file() can generate broken files on Windows. Instead, utils::download.file() recommends the usage of mode = "wb" and mode = "ab". If method = "curl" or method = "wget", no mode should be provided as it will be ignored.

Usage

download_file_linter()

See also

linters for a complete list of linters available in lintr.

Examples

# will produce lints
lint(
  text = "download.file(x = my_url)",
  linters = download_file_linter()
)
#> <text>:1:1: warning: [download_file_linter] download.file() should use mode = 'wb' or ('ab') rather than relying on the default mode = 'w'.
#> download.file(x = my_url)
#> ^~~~~~~~~~~~~

lint(
  text = "download.file(x = my_url, mode = 'w')",
  linters = download_file_linter()
)
#> <text>:1:1: warning: [download_file_linter] download.file() should use mode = 'wb' rather than mode = 'w' for portability on Windows.
#> download.file(x = my_url, mode = 'w')
#> ^~~~~~~~~~~~~

lint(
  text = "download.file(x = my_url, method = 'curl', mode = 'wb')",
  linters = download_file_linter()
)
#> <text>:1:1: warning: [download_file_linter] mode argument value is ignored for download.file(method = 'curl').
#> download.file(x = my_url, method = 'curl', mode = 'wb')
#> ^~~~~~~~~~~~~

# okay
lint(
  text = "download.file(x = my_url, mode = 'wb')",
  linters = download_file_linter()
)
#>  No lints found.

lint(
  text = "download.file(x = my_url, method = 'curl')",
  linters = download_file_linter()
)
#>  No lints found.