❯ checking R code for possible problems ... NOTE
check_plausibility_mfaz: warning in sexRatioTest({: partial argument
match of 'code' to 'codes'
check_plausibility_mfaz: warning in {: partial argument match of 'code'
to 'codes'
check_plausibility_mfaz: warning in sex: partial argument match of
'code' to 'codes'
check_plausibility_mfaz: warning in }: partial argument match of 'code'
to 'codes'
check_plausibility_mfaz: warning in }, code = c(1, 2)): partial
argument match of 'code' to 'codes'
check_plausibility_muac: warning in sexRatioTest({: partial argument
match of 'code' to 'codes'
check_plausibility_muac: warning in {: partial argument match of 'code'
to 'codes'
check_plausibility_muac: warning in sex: partial argument match of
'code' to 'codes'
check_plausibility_muac: warning in }: partial argument match of 'code'
to 'codes'
check_plausibility_muac: warning in }, code = c(1, 2)): partial
argument match of 'code' to 'codes'
check_plausibility_wfhz: warning in sexRatioTest({: partial argument
match of 'code' to 'codes'
check_plausibility_wfhz: warning in {: partial argument match of 'code'
to 'codes'
check_plausibility_wfhz: warning in sex: partial argument match of
'code' to 'codes'
check_plausibility_wfhz: warning in }: partial argument match of 'code'
to 'codes'
check_plausibility_wfhz: warning in }, code = c(1, 2)): partial
argument match of 'code' to 'codes'
0 errors ✔ | 0 warnings ✔ | 1 note ✖
[ ] TESTING: review code coverage and see if uncovered lines can be tested
on review of your testing suite
You are fond of using local() - not sure where you got this - I reviewd Hadley's work again and this is not something from him. Whilst I can see the reason for using local(), it needs to be made clear as well that the testthat() mechanism runs in its own environment separate from the package environment (see https://r-pkgs.org/testing-design.html#sec-testing-design-principles)
I suggest moving the top level code you have been putting inside local() into the test context itself like this:
On testing whether inputs to functions are of the right class/type
in the package-review branch, I created a test called test-input-checks.R to show a minimal example of class/type checking for functions.
test_that("inputs are checked for type and/or class", {
## Age functions (exported only) ----
test_data <- data.frame(
survey_date = Sys.Date(),
dob = c(
"2000-01-01", "2020-01-01", "01-01-2022", "Jan-01-2021",
"01-January-2023", "January-01-2021", "20-01-01", "01-01-22"
),
age = NA_character_
)
expect_error(
process_age(
df = test_data, svdate = "survey_date", birdate = "dob", age = "age"
),
regexp = "dob not a Date object"
)
})
With this test, what I want to reinforce is this idea that functions needs to check for the input class/type to ensure that what is being provided by user is correct input.
In your process_age() function, you have 2 parameters that require dates but in your documentation, you don't indicate that these dates need to be Date objects. You even say in your documenation "day, month year" so users might think this is the format that dates need to be given. The test I created above tests whether your function will throw an appropriate error if the dates in the input are in different formats and are character class/type.
Your package doesn't throw its own error. It errors on age because age in NAcharacter which again your package should specific error on with a message rather than relying on an obscure base error message.
Review Comments
On
devtools::check()
, I see:To learn about partial matching in R, see https://stat.ethz.ch/pipermail/r-devel/2024-April/083344.html.
For this I would recommend using the correct name of the argument
code
tocodes
.on
devtools::check_win_devel()
, results have been emailed totomas.zaba@outlook.com
on
devtools::check_win_oldrelease()
, results have been emailed totomas.zaba@outlook.com
on
devtools::check_win_release()
, results have been emailed totomas.zaba@outlook.com
on
rhub::rhub_check()
on
devtools::test_coverage()
, I see:on review of your testing suite
You are fond of using
local()
- not sure where you got this - I reviewd Hadley's work again and this is not something from him. Whilst I can see the reason for usinglocal()
, it needs to be made clear as well that thetestthat()
mechanism runs in its own environment separate from the package environment (see https://r-pkgs.org/testing-design.html#sec-testing-design-principles)I suggest moving the top level code you have been putting inside
local()
into the test context itself like this:On testing whether inputs to functions are of the right class/type
package-review
branch, I created a test calledtest-input-checks.R
to show a minimal example of class/type checking for functions.With this test, what I want to reinforce is this idea that functions needs to check for the input class/type to ensure that what is being provided by user is correct input.
In your
process_age()
function, you have 2 parameters that require dates but in your documentation, you don't indicate that these dates need to beDate
objects. You even say in your documenation "day, month year" so users might think this is the format that dates need to be given. The test I created above tests whether your function will throw an appropriate error if the dates in the input are in different formats and are character class/type.Your package doesn't throw its own error. It errors on age because age in NAcharacter which again your package should specific error on with a message rather than relying on an obscure base error message.