Skip to content

Commit

Permalink
rename objects in tests, maybe fixes random test order
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Sep 7, 2023
1 parent a2c233c commit f01ef4b
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions tests/testthat/test-recode_into.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,57 +189,57 @@ test_that("recode_into, make sure recode works with missing in original variable
data(mtcars)
mtcars$mpg[c(3, 10, 12, 15, 16)] <- NA
mtcars$cyl[c(2, 15, 16)] <- NA
d <<- as.data.frame(mtcars)
out1 <- recode_into(
d$mpg > 20 & d$cyl == 6 ~ 1,
d$mpg <= 20 ~ 2,
d$cyl == 4 ~ 3,
d_recode_na <<- as.data.frame(mtcars)
out1_recoded_na <- recode_into(
d_recode_na$mpg > 20 & d_recode_na$cyl == 6 ~ 1,
d_recode_na$mpg <= 20 ~ 2,
d_recode_na$cyl == 4 ~ 3,
default = 0
)
out2 <- recode_into(
d$mpg > 20 & d$cyl == 6 ~ 1,
d$mpg <= 20 ~ 2,
out2_recoded_na <- recode_into(
d_recode_na$mpg > 20 & d_recode_na$cyl == 6 ~ 1,
d_recode_na$mpg <= 20 ~ 2,
default = 0
)
out3 <- recode_into(
d$mpg > 20 & d$cyl == 6 ~ 1,
d$mpg <= 20 ~ 2,
d$cyl == 4 ~ 3,
out3_recoded_na <- recode_into(
d_recode_na$mpg > 20 & d_recode_na$cyl == 6 ~ 1,
d_recode_na$mpg <= 20 ~ 2,
d_recode_na$cyl == 4 ~ 3,
default = 0,
preserve_na = FALSE
)
out4 <- recode_into(
d$mpg > 20 & d$cyl == 6 ~ 1,
d$mpg <= 20 ~ 2,
out4_recoded_na <- recode_into(
d_recode_na$mpg > 20 & d_recode_na$cyl == 6 ~ 1,
d_recode_na$mpg <= 20 ~ 2,
default = 0,
preserve_na = FALSE
)
# one NA in mpg is overwritten by valid value from cyl, total 5 NA
expect_identical(
out1,
out1_recoded_na,
c(
1, NA, 3, 1, 2, 2, 2, 3, 3, NA, 2, NA, 2, 2, NA, NA, 2, 3,
3, 3, 3, 2, 2, 2, 2, 3, 3, 3, 2, 2, 2, 3
)
)
# total 6 NA
expect_identical(
out2,
out2_recoded_na,
c(
1, NA, NA, 1, 2, 2, 2, 0, 0, NA, 2, NA, 2, 2, NA, NA, 2, 0,
0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 2, 2, 2, 0
)
)
# NA is preserved, set to default if not overwritten by other recodes
expect_identical(
out3,
out3_recoded_na,
c(
1, 0, 3, 1, 2, 2, 2, 3, 3, 0, 2, 0, 2, 2, 0, 0, 2, 3, 3, 3,
3, 2, 2, 2, 2, 3, 3, 3, 2, 2, 2, 3
)
)
expect_identical(
out4,
out4_recoded_na,
c(
1, 0, 0, 1, 2, 2, 2, 0, 0, 0, 2, 0, 2, 2, 0, 0, 2, 0, 0, 0,
0, 2, 2, 2, 2, 0, 0, 0, 2, 2, 2, 0
Expand Down

0 comments on commit f01ef4b

Please sign in to comment.