-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug with
shadow_long
not working when gathering variables of mi…
…xed type. - Fix involves specifying a value transform, which defaults to character. - also update some shadow_long tests to use snapshots - Resolves #314
- Loading branch information
Showing
5 changed files
with
135 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# shadow_long returns the right dimensions and names etc | ||
|
||
Code | ||
shadow_long(ocean_shadow) | ||
Output | ||
# A tibble: 5,888 x 4 | ||
variable value variable_NA value_NA | ||
<chr> <chr> <chr> <fct> | ||
1 year 1997 year_NA !NA | ||
2 latitude 0 latitude_NA !NA | ||
3 longitude -110 longitude_NA !NA | ||
4 sea_temp_c 27.59000015 sea_temp_c_NA !NA | ||
5 air_temp_c 27.14999962 air_temp_c_NA !NA | ||
6 humidity 79.59999847 humidity_NA !NA | ||
7 wind_ew -6.400000095 wind_ew_NA !NA | ||
8 wind_ns 5.400000095 wind_ns_NA !NA | ||
9 year 1997 year_NA !NA | ||
10 latitude 0 latitude_NA !NA | ||
# i 5,878 more rows | ||
|
||
# shadow_long works gives the classes with function value transform | ||
|
||
Code | ||
shadow_long(ocean_shadow, fn_value_transform = as.numeric) | ||
Output | ||
# A tibble: 5,888 x 4 | ||
variable value variable_NA value_NA | ||
<chr> <dbl> <chr> <fct> | ||
1 year 1997 year_NA !NA | ||
2 latitude 0 latitude_NA !NA | ||
3 longitude -110 longitude_NA !NA | ||
4 sea_temp_c 27.6 sea_temp_c_NA !NA | ||
5 air_temp_c 27.1 air_temp_c_NA !NA | ||
6 humidity 79.6 humidity_NA !NA | ||
7 wind_ew -6.40 wind_ew_NA !NA | ||
8 wind_ns 5.40 wind_ns_NA !NA | ||
9 year 1997 year_NA !NA | ||
10 latitude 0 latitude_NA !NA | ||
# i 5,878 more rows | ||
|
||
# shadow_long returns right dimensions, names, etc when filtered | ||
|
||
Code | ||
shadow_long(ocean_shadow, air_temp_c, humidity) | ||
Output | ||
# A tibble: 1,472 x 4 | ||
variable value variable_NA value_NA | ||
<chr> <chr> <chr> <fct> | ||
1 air_temp_c 27.14999962 air_temp_c_NA !NA | ||
2 humidity 79.59999847 humidity_NA !NA | ||
3 air_temp_c 27.02000046 air_temp_c_NA !NA | ||
4 humidity 75.80000305 humidity_NA !NA | ||
5 air_temp_c 27 air_temp_c_NA !NA | ||
6 humidity 76.5 humidity_NA !NA | ||
7 air_temp_c 26.93000031 air_temp_c_NA !NA | ||
8 humidity 76.19999695 humidity_NA !NA | ||
9 air_temp_c 26.84000015 air_temp_c_NA !NA | ||
10 humidity 76.40000153 humidity_NA !NA | ||
# i 1,462 more rows | ||
|
||
# shadow_long returns right dimensions, names, etc when filtered with function value transform | ||
|
||
Code | ||
shadow_long(ocean_shadow, air_temp_c, humidity, fn_value_transform = as.numeric) | ||
Output | ||
# A tibble: 1,472 x 4 | ||
variable value variable_NA value_NA | ||
<chr> <dbl> <chr> <fct> | ||
1 air_temp_c 27.1 air_temp_c_NA !NA | ||
2 humidity 79.6 humidity_NA !NA | ||
3 air_temp_c 27.0 air_temp_c_NA !NA | ||
4 humidity 75.8 humidity_NA !NA | ||
5 air_temp_c 27 air_temp_c_NA !NA | ||
6 humidity 76.5 humidity_NA !NA | ||
7 air_temp_c 26.9 air_temp_c_NA !NA | ||
8 humidity 76.2 humidity_NA !NA | ||
9 air_temp_c 26.8 air_temp_c_NA !NA | ||
10 humidity 76.4 humidity_NA !NA | ||
# i 1,462 more rows | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,30 @@ | ||
aq_shadow <- nabular(airquality) | ||
ocean_shadow <- nabular(oceanbuoys) | ||
|
||
aq_sh_long <- shadow_long(aq_shadow) | ||
|
||
test_that("shadow_long returns data of the right dimensions", { | ||
expect_equal(dim(aq_sh_long), c(918, 4)) | ||
}) | ||
|
||
test_that("shadow_long returns data with the right names", { | ||
expect_equal(names(aq_sh_long), | ||
c("variable", "value", "variable_NA", "value_NA")) | ||
}) | ||
library(purrr) | ||
|
||
test_that("shadow_long returns right data class", { | ||
expect_equal(as.character(map_chr(aq_sh_long, class)), | ||
c("character", "numeric", "character", "factor")) | ||
test_that("shadow_long returns the right dimensions and names etc", { | ||
expect_snapshot( | ||
shadow_long(ocean_shadow) | ||
) | ||
}) | ||
|
||
aq_sh_long_ozone <- shadow_long(aq_shadow, Ozone) | ||
|
||
test_that("shadow_long returns data with right dimensions when filtered", { | ||
expect_equal(dim(aq_sh_long_ozone), c(153, 4)) | ||
test_that("shadow_long works gives the classes with function value transform", { | ||
expect_snapshot( | ||
shadow_long(ocean_shadow, | ||
fn_value_transform = as.numeric) | ||
) | ||
}) | ||
|
||
test_that("shadow_long returns data with right names when filtered", { | ||
expect_equal(names(aq_sh_long_ozone), | ||
c("variable", "value", "variable_NA", "value_NA")) | ||
test_that("shadow_long returns right dimensions, names, etc when filtered", { | ||
expect_snapshot( | ||
shadow_long(ocean_shadow, air_temp_c, humidity) | ||
) | ||
}) | ||
|
||
test_that("shadow_long returns right data class when filtered", { | ||
expect_equal(as.character(map_chr(aq_sh_long_ozone, class)), | ||
c("character", "numeric", "character", "factor")) | ||
test_that("shadow_long returns right dimensions, names, etc when filtered with function value transform", { | ||
expect_snapshot( | ||
shadow_long(ocean_shadow, | ||
air_temp_c, | ||
humidity, | ||
fn_value_transform = as.numeric | ||
) | ||
) | ||
}) | ||
|
||
|
||
aq_sh_long_ozone_solar <- shadow_long(aq_shadow, Ozone, Solar.R) | ||
|
||
test_that("shadow_long returns data with right dimensions when filtered", { | ||
expect_equal(dim(aq_sh_long_ozone_solar), c(306, 4)) | ||
}) | ||
|
||
test_that("shadow_long returns data with right names when filtered", { | ||
expect_equal(names(aq_sh_long_ozone_solar), | ||
c("variable", "value", "variable_NA", "value_NA")) | ||
}) | ||
|
||
test_that("shadow_long returns right data class when filtered", { | ||
expect_equal(as.character(map_chr(aq_sh_long_ozone_solar, class)), | ||
c("character", "numeric", "character", "factor")) | ||
}) | ||
|