@@ -28,58 +28,73 @@ p <- ggplot2::ggplot(
2828) +
2929 ggplot2 :: geom_line(ggplot2 :: aes(colour = Species ))
3030
31- # test_that("easy_labs uses column attrib", {
32- #
33- # hard_res <- p + ggplot2::labs(x = 'Sepal Length', y = 'Sepal Width', colour = 'Flower Species')
34- # easy_res <- p + easy_labs()
35- #
36- # expect_mapequal(get_labs(easy_res), get_labs(hard_res))
37- # expect_message(p + easy_labs(teach = TRUE), regexp = "colour = 'Flower Species'")
38- #
39- # easy_res_test_teach <- p + easy_labs()
40- # teach_message <- capture_messages({p + easy_labs(teach = TRUE)})[2]
41- # teach_res <- rlang::eval_bare(rlang::parse_expr(teach_message))
42- # expect_eqNe(easy_res_test_teach, p + teach_res)
43- #
44- # expect_doppelganger("labels_attrib", easy_res)
45- #
46- # })
47-
48- # testthat::test_that("regular labs overides easy_labs ", {
49- #
50- # hard_res <- p + ggplot2::labs(x = 'x axis', y = 'Sepal Width', colour = 'Flower Species')
51- # easy_res <- p + easy_labs(x = 'x axis')
52- #
53- # expect_mapequal(get_labs(easy_res), get_labs(hard_res))
54- # expect_doppelganger("labels_manual", easy_res)
55- #
56- # })
57-
58- # testthat::test_that("regular labs pass new labels through easy_labs ", {
59- #
60- # hard_res <- p + ggplot2::labs(x = 'Sepal Length', y = 'Sepal Width', colour = 'Flower Species', title = 'my title')
61- # easy_res <- p + easy_labs(title = 'my title')
62- #
63- # expect_eqNe(easy_res$labels[sort(names(easy_res$labels))],
64- # hard_res$labels[sort(names(hard_res$labels))])
65- # expect_doppelganger("labels_mytitle", easy_res)
66- #
67- # })
68-
69- # test_that("column name used when no column attrib present", {
70- #
71- # labelled::var_label(iris_labs$Sepal.Length) <- NULL
72- #
73- # p <- ggplot2::ggplot(iris_labs,
74- # ggplot2::aes(x = Sepal.Length,
75- # y = Sepal.Width)) +
76- # ggplot2::geom_line(ggplot2::aes(colour = Species))
77- #
78- #
79- # hard_res <- p + ggplot2::labs(y = 'Sepal Width', colour = 'Flower Species')
80- # easy_res <- p + ggeasy::easy_labs()
81- #
82- # expect_mapequal(get_labs(easy_res), get_labs(hard_res))
83- # expect_doppelganger("labels_y_col", easy_res)
84- #
85- # })
31+ test_that(" easy_labs uses column attrib" , {
32+ skip_if(utils :: packageVersion(" ggplot2" ) > = package_version(" 3.5.2.9001" ))
33+ hard_res <- p +
34+ ggplot2 :: labs(
35+ x = ' Sepal Length' ,
36+ y = ' Sepal Width' ,
37+ colour = ' Flower Species'
38+ )
39+ easy_res <- p + easy_labs()
40+
41+ expect_mapequal(get_labs(easy_res ), get_labs(hard_res ))
42+ expect_message(
43+ p + easy_labs(teach = TRUE ),
44+ regexp = " colour = 'Flower Species'"
45+ )
46+
47+ easy_res_test_teach <- p + easy_labs()
48+ teach_message <- capture_messages({
49+ p + easy_labs(teach = TRUE )
50+ })[2 ]
51+ teach_res <- rlang :: eval_bare(rlang :: parse_expr(teach_message ))
52+ expect_eqNe(easy_res_test_teach , p + teach_res )
53+
54+ expect_doppelganger(" labels_attrib" , easy_res )
55+ })
56+
57+ testthat :: test_that(" regular labs overides easy_labs " , {
58+ skip_if(utils :: packageVersion(" ggplot2" ) > = package_version(" 3.5.2.9001" ))
59+ hard_res <- p +
60+ ggplot2 :: labs(x = ' x axis' , y = ' Sepal Width' , colour = ' Flower Species' )
61+ easy_res <- p + easy_labs(x = ' x axis' )
62+
63+ expect_mapequal(get_labs(easy_res ), get_labs(hard_res ))
64+ expect_doppelganger(" labels_manual" , easy_res )
65+ })
66+
67+ testthat :: test_that(" regular labs pass new labels through easy_labs " , {
68+ skip_if(utils :: packageVersion(" ggplot2" ) > = package_version(" 3.5.2.9001" ))
69+ hard_res <- p +
70+ ggplot2 :: labs(
71+ x = ' Sepal Length' ,
72+ y = ' Sepal Width' ,
73+ colour = ' Flower Species' ,
74+ title = ' my title'
75+ )
76+ easy_res <- p + easy_labs(title = ' my title' )
77+
78+ expect_eqNe(
79+ easy_res $ labels [sort(names(easy_res $ labels ))],
80+ hard_res $ labels [sort(names(hard_res $ labels ))]
81+ )
82+ expect_doppelganger(" labels_mytitle" , easy_res )
83+ })
84+
85+ test_that(" column name used when no column attrib present" , {
86+ skip_if(utils :: packageVersion(" ggplot2" ) > = package_version(" 3.5.2.9001" ))
87+ labelled :: var_label(iris_labs $ Sepal.Length ) <- NULL
88+
89+ p <- ggplot2 :: ggplot(
90+ iris_labs ,
91+ ggplot2 :: aes(x = Sepal.Length , y = Sepal.Width )
92+ ) +
93+ ggplot2 :: geom_line(ggplot2 :: aes(colour = Species ))
94+
95+ hard_res <- p + ggplot2 :: labs(y = ' Sepal Width' , colour = ' Flower Species' )
96+ easy_res <- p + ggeasy :: easy_labs()
97+
98+ expect_mapequal(get_labs(easy_res ), get_labs(hard_res ))
99+ expect_doppelganger(" labels_y_col" , easy_res )
100+ })
0 commit comments