golem
golem copied to clipboard
Add replace arg to use_external
We have chosen to prevent overwritting the external files when they exist, but we need to allow to force it in command line.
Maybe I am mistaken but there are four use_external_*
functions in R/use_files.R
with a threefold/almost four-fold repetition.
This may not be relevant for your issue but it seems good to reduce duplication and one could as well go ahead and standardize the behaviour in a separate/encapsulated function call before adding more clutter with an additional argument replace
. I am pretty sure there will be no breaking changes as it is really a repetition...
Here is what I suggest (and happy to do this of course):
-
use_external_js_file
anduse_external_css_file
are doing the same except for having a different ending ("js" vs "css") and printing behaviour -
use_external_html_template
is doing almost the same as those above the with difference that- in the end,
cat_download(where)
is called separately instead of making the call insidefile_created_dance(..., catfun = cat_downloaded)
(which the others do); I do not think this is necessary, it seems like an artefact - in the beginning it is not checking for
missing()
"name" argument as there is a default provided, but adding the missing part would never harm - in the middle there is a missing
if(file.ext()
check (why? it seems to be easy to provide a default one)
- in the end,
- The fourth function
use_external_file()
is a bit different:- the first part makes the name check before the
missing
which seems like a hidden bug (at least compared to the otheruse_external
funcs) , and defines the on-exit behavoiur not at the very beginning for no reasons:
check_name_length(name) if (missing(name)) { name <- basename(url) } old <- setwd(fs_path_abs(pkg)) on.exit(setwd(old))
- it skips the creation of
new_file
which may be expected behaviour; but that could as well be handled with an optional argument of an encapsulated function, or simply performed for consistency reasons
- the first part makes the name check before the
Now that is a threefold (see (1) and (2)), almost four-fold repetition if you include (3).
What do yo uthink ?