curlconverter / curlconverter

Transpile curl commands into Python, JavaScript and 27 other languages
https://curlconverter.com
MIT License
7.17k stars 867 forks source link

[r] require-vs-library #636

Closed r2evans closed 3 months ago

r2evans commented 3 months ago

The suggested R code starts with require(httr). While that may work, it is misusing the require function, as it can return FALSE (the package is not installed/available) but provide no error to the user. It is almost always better (especially in this type of use) to use library(httr) instead, as it will emit an error if the function is not available.

An alternative is

if (!require("httr")) {
  # do something here, perhaps
  install.packages("httr")
  library(httr)
}

Refs:

Thanks.

verhovsky commented 3 months ago

Thanks, I changed it to library(httr) in https://github.com/curlconverter/curlconverter/commit/07559b5c44c24cf15ad236aec56d36957d32c92c and https://github.com/curlconverter/curlconverter/commit/598d3c4a5a58ac97b0662d338490e835f74edcea .