benmarwick / rrtools

rrtools: Tools for Writing Reproducible Research in R
Other
670 stars 85 forks source link

create_compendium("pkgname") doesn't check whether "pkgname" already exists #102

Closed soniamitchell closed 4 years ago

soniamitchell commented 4 years ago

Describe the bug The function create_compendium("pkgname") doesn't check whether "pkgname" already exists. If pkgname is a folder, the package is merged with an existing folder. If pkgname is a file, an error occurs.

To Reproduce

  1. In terminal, create file '~/Desktop/pkgname'
  2. > create_compendium('pkgname')
    Error in writeLines(c("cat(crayon::bold('\nThis project was set up by rrtools.\n'))",  : 
    cannot open the connection
    In addition: Warning messages:
    1: In dir.create(path) : 'pkgname' already exists
    2: In writeLines(c("cat(crayon::bold('\nThis project was set up by rrtools.\n'))",  :
    cannot open file 'pkgname/.Rprofile': Not a directory
    >

Expected behavior Check whether 'pkgname' already exists and if it does, stop.

benmarwick commented 4 years ago

Thanks, that does seem like something we could handle more gracefully. Do you have something in mind for a fix? Is there another package that does this very well which we can look at for inspiration?

soniamitchell commented 4 years ago

Maybe something like this:

if (!dir.exists(path)){
dir.create(path)
} else {
    print("Directory already exists!")
}

at line 89 in core_use_compendium.R ?

benmarwick commented 4 years ago

Thank you, would you like to make a pull request (with a test) to add this?