r-lib/rprojroot

FR: find_root if exists without error

ctbrown opened this issue · 3 comments

I know this is small and happy to provide this as PR, bur there are occasions when it would be nice to test for a root without getting the error that find_root() throws. It could be as simple as:

find_root_safe <- function(...) { 
        x <- NULL 
       try( x <- find_root(...), silent=TRUE )
      return(x)
 }

Thanks. I'm open to a PR that implements has_root(), but the try() approach doesn't look safe to me. How about converting find_root() to a function that returns a string with an optional error attribute, and then implementing find_root() and has_root() as very thin wrappers that call that function? Please also update root_criterion() to include a has_file() member function (constructed similarly to find_file()).

In most use cases, if there's no root an error is the right thing.

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.