Skip to content

Conversation

@PhilBoileau
Copy link
Collaborator

This PR provides functions for running testthat tests stored in the tests/testthat directory of a simChef simulation study. This is accomplished through two new functions:

  • run_tests(): This function searches for tests/testthat.R. If it finds this file, then it is ran. Otherwise, an error message stating that the file can't be found is printed to the console.
  • test_sim_dir(): This function wraps around testthat::test_dir(), running the dgp-, method-, evaluator- and visualizer-related tests in their respective directories. If using create_sim(), this function is automatically added to tests/testthat.R.

These functions are somewhat brittle. They work best with simulation studies created with create_sim(). If they are adopted, we'll need to modify documentation, like the "Setting Up Your Simulation" vignette, such that users are advised to generate new simulation projects with create_sim().

@PhilBoileau
Copy link
Collaborator Author

We need to include a function that automatically loads all the functions defined in the R/ subdirectories, similar to pkgload::load_all(). It would be called in tests/testthat.R, though it might be helpful in other situations too.

Something like this should work:

load_all_sim_functions <- function() {
  sim_functions_files = list.files(
    c("R/dgp", "R/method", "R/eval", "R/viz"),
    pattern = "*.R$", full.names = TRUE, ignore.case = TRUE
  )
  sapply(sim_functions_files, source)
}

@jpdunc23
Copy link
Contributor

jpdunc23 commented Apr 26, 2023

@PhilBoileau This is awesome! Hopefully we can get it merged in before the JOSS submission.

A few of TODOs:

  • Add any missing package dependencies to DESCRIPTION in the Imports field; the one I noticed from the failing tests is testthat needs to be moved from Suggests to Imports, which may be all that's missing.
  • Remove @importFrom from Roxygen comments. Instead, using package::function syntax (which I see you already are) is sufficient.
  • I think using internal function from other packages via ::: is a no-go for R CMD check (see here), so we need to replace those functions with some alternative, either from a public API or by copying the other package's internal code to simChef. I'd prefer to avoid the latter, but it's fine if need be.

Let me know if you have any questions or want some help with these!

@PhilBoileau
Copy link
Collaborator Author

Sounds good, thanks for these pointers! I'll try to knock these out by early next week.

On the last TODO: I think I had left that there so that we could discuss the best path forward. We could try reaching out to package maintainers to see if they'd consider exporting the functions we need. In the meantime, we can copy these internal functions into simChef. How does that sound?

@tiffanymtang
Copy link
Collaborator

Thanks so much, Phil! What are your thoughts on using usethis:: use_git() instead of use_git_no_ask()? I think this would avoid all instances of :::. The issue is I'm not familiar enough with usethis::use_git() nor use_git_no_ask() to understand if the added benefit of use_git_no_ask() is worth figuring out how to workaround the :::.

@PhilBoileau
Copy link
Collaborator Author

PhilBoileau commented Apr 28, 2023

Thanks for taking a look, @tiffanymtang! I unfortunately don't remember why I opted for use_git_no_ask() instead of usethis::use_git(), but I do know that the latter wasn't working. I'll surely remember why as I work through these TODOs. I'll report back here with my reasoning.

@PhilBoileau
Copy link
Collaborator Author

Just finished making the requested changes, @jpdunc23 and @tiffanymtang. I had replaced usethiss::use_git() by use_git_no_ask() because the former asks the user whether they want to commit the newly created files. Past-Phil must have wanted these files to be commited automatically. I don't think it's an issue though.

@PhilBoileau
Copy link
Collaborator Author

I'll update the "Setting Up Your Simulation Study" vignette to reflect these additions. I'll ping you both once that's done for a review.

Copy link
Collaborator

@tiffanymtang tiffanymtang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks so much, Phil! I think it's fine to merge into main even though there's a strange error in one of the tests. I will look into that later.

@PhilBoileau
Copy link
Collaborator Author

Thanks for reviewing, @tiffanymtang! Will do.

@PhilBoileau PhilBoileau merged commit d9ced3c into main May 3, 2023
@tiffanymtang tiffanymtang deleted the testthat-integration branch January 2, 2025 03:24
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

Successfully merging this pull request may close these issues.

4 participants