Public-Health-Scotland / phsmethods

An R package to standardise methods used in Public Health Scotland (https://public-health-scotland.github.io/phsmethods/)
https://public-health-scotland.github.io/phsmethods/
54 stars 13 forks source link

File sizes #7

Closed jackhannah95 closed 4 years ago

jackhannah95 commented 4 years ago

This is mostly creating file_size, some tests for it, and adding some files used in the tests. Thinking of tests for this was quite hard so let me know if you have any good ideas.

I also created a phimethods.R script for some package-level documentatin. It's mainly just to include the line if(getRversion() >= "2.15.1") utils::globalVariables(c(".")) which stops a note appearing during R CMD check about . being an undefined variable.

Also added some code from @alan-y to .travis.yml to test on old and development versions of R.

alan-y commented 4 years ago

one option to test is to create a directory within the inst folder of your package, e.g. inst/test_files and then create put a few test files in there. Hopefully you should be able to then use these files to create unit tests - otherwise you will need to experiment with the mockery package which should be able to trick the unit tests into believing there are files actually there when there are not (see https://blog.r-hub.io/2019/10/29/mocking/)

jackhannah95 commented 4 years ago

I basically just copied the way readr and readxl do their tests by saving all the files inside the testthat folder and using testthat::test_path to refer to them. It seems to work alright so hopefully nothing complicated like mocking will be required, but I found this quite a hard function to think up tests for.

alan-y commented 4 years ago

ah didn't know about that, sounds like the best solution so will keep it in mind cheers!