golem icon indicating copy to clipboard operation
golem copied to clipboard

Check that the names are unique when passing to file creation.

Open ColinFay opened this issue 3 years ago • 2 comments

When passing multiple arguments to the functions, the function will fail.

colin:golem colin$ cd /tmp/
colin:tmp colin$ Rscript -e "golem::create_golem('pouet')"
── Checking package name 
✔ Valid package name
── Creating dir 
✔ Created package directory
── Copying package skeleton 
✔ Copied app skeleton
── Setting the default config 
✔ Configured app
── Running project hook function 
✔ All set
✔ Setting active project to '/private/tmp/pouet'
── Done 
A new golem named pouet was created at /private/tmp/pouet .
To continue working on your app, start editing the 01_start.R file.
colin:tmp colin$ cd pouet/
colin:pouet colin$ Rscript -e "golem::add_module(c('plif', 'plouf'))"
Error in file(file, ifelse(append, "a", "w")) : 
  invalid 'description' argument
Calls: <Anonymous> ... module_template -> write_there -> write -> cat -> file
In addition: Warning messages:
1: In if (!file_exists(where)) { :
  the condition has length > 1 and only the first element will be used
2: In if (file == "") file <- stdout() else if (startsWith(file, "|")) { :
  the condition has length > 1 and only the first element will be used
3: In if (startsWith(file, "|")) { :
  the condition has length > 1 and only the first element will be used
Execution halted
colin:pouet colin$ ls
DESCRIPTION     NAMESPACE       R               dev             inst            man
colin:pouet colin$ Rscript -e "golem::add_module(c('plif'))"
✔ File already exists.
• Go to R/mod_plif.R

Should these functions:

  • Take only the first value of the vector or
  • Fail gracefully

ColinFay avatar Nov 05 '21 10:11 ColinFay

I think we should fail gracefully.

attempt::stop_if(name, ~ length(.x) > 1, "Name should be of length 1")

ColinFay avatar Nov 05 '21 10:11 ColinFay

Other idea, vectorized versions :

golem::add_modules()
golem::add_css_files()
etc.

ColinFay avatar Nov 05 '21 10:11 ColinFay