@@ -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