dark-peak-analytics / assertHE

R package to assist in the verification of health economic decision models.
https://dark-peak-analytics.github.io/assertHE/
Other
4 stars 10 forks source link

Account for potential .rds files in the testthat/fixtures folder. #36

Closed nialldavison closed 7 months ago

nialldavison commented 8 months ago

When trying to run the summarise_model and visualise_project commands on a project, R returned an error stating "invalid multibyte character in parser" for an .rds file found in the testthat/fixtures folder. This folder helps the user to store objects when it’s not practical to make tests entirely self-sufficient.

The error traces to the parse command that is run as part of the find_function_calls_in_file function. I assume that since tests would not be stored within the testthat/fixtures folder, and there is no need to try to parse the .rds files, you can reasonably remove references to these files from this portion of the code.

RobertASmith commented 7 months ago

Hi Niall,

Thanks so much for raising this issue, I'd completely overlooked it. The package is still very much in development but I'm glad you gave it a go.

When I tried to run the tests from your fork I get a fail, basically because if there is no fixtures files then it'll exclude nothing and return an empty vector (see GitHub actions CI checks which I've enabled for your fork).

However, I think I understand the issue you are facing, and have solved this by adding pattern = "\\.R$" to the list.files function call. This will only read R files from the list of files.

  v_test_file_paths <-
    list.files(path = test_folder,
               recursive = TRUE,
               full.names = TRUE,
               pattern = "\\.R$")

I've added in an example .rds file in the fixtures folder to check that this works going forward.

Thanks again, if you could sync from main again soon and see if my solution works for your model that would be great. If it doesn't I can investigate tomorrow.

Kind regards,

Rob

nialldavison commented 7 months ago

Hi Rob,

Thank you for the quick reply and solution. I hadn't tested the code on projects without a fixtures folder! Can confirm your changes work for my project.

Best wishes, Niall