Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working directory friction #214

Closed
wlandau opened this issue Nov 5, 2021 · 4 comments
Closed

Working directory friction #214

wlandau opened this issue Nov 5, 2021 · 4 comments

Comments

@wlandau
Copy link

wlandau commented Nov 5, 2021

valtools seems to require the working directory to be the root of the validation file space, not the root of the package. If I try this command, but with name equal to file.path("r_pharma_validation", "req1.md") and my working directory one level up, I get an error and warnings. This took a few minutes to debug during the workshop today.

packageVersion("valtools")
#> [1] ‘0.4.0’
getwd()
#> [1] "/cloud/project/Materials/Materials-04-Requirements_Report"
vt_use_req(
  file.path("r_pharma_validation", "req1.md"),
  username = "useR",
  title = "Requirement 1",
  open = TRUE
)
#> Error: Failed to create validationrequirementsr_pharma_validation/req1.md 
#> Run `rlang::last_error()` to see where the error occurred.
#> In addition: Warning messages:
#> 1: In if (file.exists(item_file_path)) { :
#>   the condition has length > 1 and only the first element will be used
#> 2: In if (!dir.exists(file.path(validation_directory, type))) { :
#>   the condition has length > 1 and only the first element will be used
@thebioengineer
Copy link
Collaborator

thebioengineer commented Nov 5, 2021

The root can either be the package root directory or within the packet directory.

This is a weird error we thought we had solved (ISSUE #204, PR #210), but apparently not. I will investigate.

@thebioengineer
Copy link
Collaborator

I think I sorted out what is going on - it is supposed to throw an error if the function is called outside of a package/packet.

However, because the workshop is a project overall, it finds and sets the root to the workshops root. When it searches for the config, it finds all the various config files within the workshop, and lists all of them. Which leads to your error, @wlandau, because the path gets sent to create_item() (a helper function under valtools).

reprex code:

library(valtools)
library(testthat)

test_that("Informative error when inside an Rproj, but packet or package is nested in a subfolder", {
  
  withr::with_tempdir({
    
    quiet <- capture.output({
      usethis::create_project("test_project",open = FALSE)
      vt_create_packet("test_project/example_packet", 
                         target = "example.package",
                         open = FALSE)
      vt_create_packet("test_project/example_packet2", 
                       target = "example.package",
                       open = FALSE)
    })
    
    
    withr::with_dir(new = "test_project", {
     expect_error(
      vt_find_config(),
      paste0(
      "Could not find root directory. ",
      "Is your working directory inside a package, validation packet, or project?\n"
      ),
      fixed = TRUE)
      
    })
    
  })
  
})

@thebioengineer
Copy link
Collaborator

@wlandau, would it have been useful for an error to point to the fact that you were in a situation of nested projects, and you needed to change directories? I have a PR opened in #217 that makes it so it would give an error like below:

Error: Nested projects with validation infrastructures exist. Set the working directory to one of:
	- `setwd("r_pharma_validation")`
	- `setwd("example_packet2")`

@wlandau
Copy link
Author

wlandau commented Nov 9, 2021

Yes, that definitely would have helped. I was confused about what working directory I needed, especially since the workshop example was not part of an R package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants