Skip to content

Commit a3bf8b2

Browse files
authored
Merge pull request #40 from erblast/39_ggplot2v4p0
39 ggplot2v4p0 parcats checks currently disabled
2 parents c327f1c + 1dad348 commit a3bf8b2

File tree

67 files changed

+757
-719
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+757
-719
lines changed

.github/workflows/parcats.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ on:
44
push:
55
branches: [main, master]
66
pull_request:
7-
branches: [main, master]
8-
workflow_dispatch:
97

10-
name: test-coverage
8+
name: test-coverage.yaml
9+
10+
permissions: read-all
1111

1212
jobs:
1313
test-coverage:
@@ -16,36 +16,47 @@ jobs:
1616
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
1717

1818
steps:
19-
- uses: actions/checkout@v3
19+
- uses: actions/checkout@v4
2020

2121
- uses: r-lib/actions/setup-r@v2
2222
with:
2323
use-public-rspm: true
2424

2525
- uses: r-lib/actions/setup-r-dependencies@v2
2626
with:
27-
extra-packages: any::covr
27+
extra-packages: any::covr, any::xml2
2828
needs: coverage
2929

3030
- name: Test coverage
3131
run: |
32-
covr::codecov(
32+
cov <- covr::package_coverage(
3333
quiet = FALSE,
3434
clean = FALSE,
3535
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
3636
)
37+
print(cov)
38+
covr::to_cobertura(cov)
3739
shell: Rscript {0}
3840

41+
- uses: codecov/codecov-action@v5
42+
with:
43+
# Fail if error if not on PR, or if on PR and token is given
44+
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
45+
files: ./cobertura.xml
46+
plugins: noop
47+
disable_search: true
48+
token: ${{ secrets.CODECOV_TOKEN }}
49+
3950
- name: Show testthat output
4051
if: always()
4152
run: |
4253
## --------------------------------------------------------------------
43-
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
54+
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
4455
shell: bash
4556

4657
- name: Upload test results
4758
if: failure()
48-
uses: actions/upload-artifact@v3
59+
uses: actions/upload-artifact@v4
4960
with:
5061
name: coverage-test-failures
51-
path: ${{ runner.temp }}/package
62+
path: ${{ runner.temp }}/package

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: easyalluvial
22
Title: Generate Alluvial Plots with a Single Line of Code
3-
Version: 0.3.2
3+
Version: 0.4
44
Authors@R: person( "Bjoern", "Koneswarakantha", role = c("aut","cre"), email = "datistics@gmail.com", comment = c(ORCID = "0000-0003-4585-7799") )
55
URL: https://github.com/erblast/easyalluvial/
66
Description: Alluvial plots are similar to sankey diagrams and visualise categorical data
@@ -39,7 +39,7 @@ Suggests:
3939
rpart,
4040
glmnet,
4141
xgboost
42-
RoxygenNote: 7.2.3
42+
RoxygenNote: 7.3.2
4343
Imports:
4444
purrr
4545
, tidyr (>= 1.0.0)

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export(get_data_space)
1313
export(get_pdp_predictions)
1414
export(manip_bin_numerics)
1515
export(manip_factor_2_numeric)
16+
export(manip_get_ggplot_data)
1617
export(palette_filter)
1718
export(palette_increase_length)
1819
export(palette_plot_intensity)

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Version 0.4.0 20250825
2+
- adapted to changes in ggplot2 v4.0.0
3+
14
# Version 0.3.2 submitted to CRAN 20231207
25
- check for vip pkg installation before executing example of alluvial_model_response_parsnip
36
- option for using geom_text instead of geom_label (by https://github.com/gernophil)

R/alluvial_long.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,9 @@ alluvial_long = function( data
459459
theme( axis.text.x = element_text( angle = 90, vjust = 0.5 , hjust = 0 ) )
460460
}
461461

462-
p$data_key = data_key
463-
p$alluvial_type = 'long'
464-
p$alluvial_params = params
462+
attr(p, "data_key") <- data_key
463+
attr(p, "alluvial_type") <- 'long'
464+
attr(p, "alluvial_params") <- params
465465

466466
return(p)
467467
}

R/alluvial_model_response.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -919,8 +919,11 @@ alluvial_model_response = function(pred, dspace, imp, degree = 4
919919
p = p +
920920
labs(title = title, subtitle = subtitle, caption = caption)
921921

922-
p$alluvial_type = 'model_response'
923-
p$alluvial_params = c(p$alluvial_params[! names(p$alluvial_params) %in% names(params)], params)
922+
attr(p, "alluvial_type") <- 'model_response'
923+
attr(p, "alluvial_params") <- c(
924+
attr(p, "alluvial_params")[! names(attr(p, "alluvial_params")) %in% names(params)],
925+
params
926+
)
924927

925928
return(p)
926929

@@ -1110,8 +1113,7 @@ alluvial_model_response_caret = function(train, data_input, degree = 4, bins = 5
11101113
#' m <- parsnip::rand_forest(mode = "regression") %>%
11111114
#' parsnip::set_engine("randomForest")
11121115
#'
1113-
#' rec_prep = recipes::recipe(disp ~ ., df) %>%
1114-
#' recipes::prep()
1116+
#' rec_prep = recipes::recipe(disp ~ ., df)
11151117
#'
11161118
#' wf <- workflows::workflow() %>%
11171119
#' workflows::add_model(m) %>%
@@ -1173,7 +1175,7 @@ alluvial_model_response_parsnip = function(m, data_input, degree = 4, bins = 5
11731175
imp = .f_imp(m) %>%
11741176
select(Variable, Importance)
11751177
} else {
1176-
imp = workflows::pull_workflow_fit(m) %>%
1178+
imp = workflows::extract_fit_parsnip(m) %>%
11771179
.f_imp() %>%
11781180
select(Variable, Importance)
11791181
}
@@ -1231,4 +1233,3 @@ alluvial_model_response_parsnip = function(m, data_input, degree = 4, bins = 5
12311233
}
12321234

12331235

1234-

R/alluvial_wide.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,9 @@ alluvial_wide = function( data
403403

404404
})
405405

406-
p$data_key = data_key
407-
p$alluvial_type = 'wide'
408-
p$alluvial_params = params
406+
attr(p, 'alluvial_type') = 'wide'
407+
attr(p, 'alluvial_params') = params
408+
attr(p, 'data_key') = data_key
409409

410410
return(p)
411411
}

R/expect_doppelganger.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
expect_doppelganger <- function(title, fig, path = NULL, ...) {
1+
expect_doppelganger <- function(title, fig, ...) {
22
testthat::skip_if_not_installed("vdiffr")
3-
vdiffr::expect_doppelganger(title, fig, path = path, ...)
3+
vdiffr::expect_doppelganger(title, fig, ...)
44
}

R/manip.R

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ manip_bin_numerics = function(x
164164
# labels
165165

166166
df = df %>%
167-
mutate_if(is.factor, fct_explicit_na, na_level = NA_label ) %>%
167+
mutate_if(is.factor, manip_explicit_na, na_level = NA_label ) %>%
168168
left_join( select(df_old, one_of( c(numerics, 'easyalluvialid') ) ), by = 'easyalluvialid')
169169

170170
for(num in numerics){
@@ -185,7 +185,7 @@ manip_bin_numerics = function(x
185185

186186
df = df %>%
187187
mutate_if(is.numeric, as.factor ) %>%
188-
mutate_if(is.factor, fct_explicit_na, na_level = NA_label ) %>%
188+
mutate_if(is.factor, manip_explicit_na, na_level = NA_label ) %>%
189189
rename_at( vars( ends_with('.y') ) , .funs = function(x) str_replace(x, '\\.y$', '') )
190190

191191
return(df)
@@ -239,8 +239,8 @@ manip_bin_numerics = function(x
239239
}
240240

241241
#remove easyalluvialid
242-
data_new = select(data_new, columns) %>%
243-
mutate_if( is.factor, fct_explicit_na, na_level = NA_label )
242+
data_new = select(data_new, all_of(columns)) %>%
243+
mutate_if( is.factor, manip_explicit_na, na_level = NA_label )
244244

245245
if( input_vector ){
246246
return( data_new$x )
@@ -291,3 +291,31 @@ check_empty_lvl <- function(col, df){
291291
}
292292
}
293293

294+
295+
#' Get ggplot data
296+
#'@description retrieve ggplot 2 plot data from S3 and S7 (>= ggplot2 v4.0)
297+
#'@param p ggplot object
298+
#'@export
299+
manip_get_ggplot_data <- function(p) {
300+
data <- if (inherits(p, "ggplot2::ggplot")) {
301+
p@data
302+
} else if (inherits(p, "ggplot")) {
303+
p$data
304+
} else {
305+
stop("p needs to be a ggplot object")
306+
}
307+
}
308+
309+
#' Make NA levels explicit
310+
#' @description fct_na_value_to_level will create a NA level even there is
311+
#' none present to begin with
312+
#'@keywords internal
313+
manip_explicit_na <- function(f, na_level) {
314+
315+
if (anyNA(f)) {
316+
f <- forcats::fct_na_value_to_level(f, level = na_level)
317+
}
318+
319+
return(f)
320+
}
321+

0 commit comments

Comments
 (0)