r-lib / rprojroot

Finding files in project subdirectories
https://rprojroot.r-lib.org/
Other
149 stars 23 forks source link

Add helper.R testing example. Fixes #26 #30

Closed BarkleyBG closed 6 years ago

BarkleyBG commented 6 years ago

I tried to keep it short and sweet. Let me know what you think?

codecov[bot] commented 6 years ago

Codecov Report

Merging #30 into master will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #30   +/-   ##
=======================================
  Coverage   95.48%   95.48%           
=======================================
  Files           5        5           
  Lines         155      155           
=======================================
  Hits          148      148           
  Misses          7        7

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 71bd742...c268a9e. Read the comment docs.

krlmlr commented 6 years ago

Thanks. It feels that this has applications beyond testing: Basically in any situation where you want to lookup files in a known subdirectory. I wonder if we should add a subdir argument to the make_find_file() and make_fix_file() accessors, and extend the vignette accordingly.

BarkleyBG commented 6 years ago

I was looking into the guts to see if I could understand the make_find_file() and make_fix_file() better. I still don't fully understand all the moving parts, so I don't know if I can respond to your suggestion to add the subdir argument.

I'd be happy to keep thinking on your comment re: subdir argument, but I'm not sure how much help I am at this moment.

BarkleyBG commented 6 years ago

While I was reading around the guts, I put some pieces together in my understanding of the package, and I thought that it would be good to expand upon the vignette's first example a little bit, which I did here. You'll note that I didn't attempt to mimic the working directory issues by explicity calling setwd() or anything, but I thought this was a clean-ish way to demonstrate how rprojroot can help stop the working directory insanity.

BarkleyBG commented 6 years ago

In general, my understanding is that rprojroot has two actions:

  1. Finds the root file
    • this is the most important action, really
  2. Uses a wrapper to file.path() to specify relative paths from the root to the desired file.
    • This supposes that the directory/tree structure is known.

I would imagine you could have a lot of functionality where the directory/tree structure isn't fully known, and you need to blindly search for files that match certain characteristics, but I don't think that's important at the moment. I think that this package should solve the "unknown variable working directory in a known tree/directory structure" problem (for now).

Do you think I've got the right idea here? Perhaps this helps to clarify what the features of the package should be (especially w/r/t the subdir consideration).

krlmlr commented 6 years ago

Thanks. Here's what I see:

rprojroot::is_testthat$make_fix_file()
## function (...) {
##   file.path("/.../rprojroot/tests/testthat", ...)
## }

What if we had:

rprojroot::is_testthat$make_fix_file(subdir = "testing_data")
## function (...) {
##   file.path("/.../rprojroot/tests/testthat", "testing_data", ...)
## }

That would just create the get_my_path() function:

get_my_path <- rprojroot::is_testthat$make_fix_file(subdir = "testing_data")

I think you have a good understanding of the package's goals, hope the examples made it a bit clearer what I meant with the subdir argument.

I'm fine with the first part, will merge now and revert partially. Would you like to submit a PR for the second part, maybe after we add support for subdir?

krlmlr commented 6 years ago

Decided to also keep the second section, we can tweak once we have a subdir argument. May I add you as co-author to the vignette?

BarkleyBG commented 6 years ago

I'm happy to help moving this along!

  1. Yes, I like subdir. If it's a nested subdirectory, should subdir take a list or vector argument? And could this work for e.g.:
my_subdir <- c("..", "sister_dir", "sister_subdir")
  1. Yes, please add me as co-vign-author! Thanks!

I'm out of office a little bit right now but would be happy to help where I can later this month. Feel free to tag @ me in issues and I'll respond.