Dear Biostarians,
As we all know that tidyverse
has shifted the paradigm the way R was being used then and now. And therefore, it has become necessary to learn tidyverse
to do efficient programming in R. For newcomers, it takes time to become familiar with tools given in tidyverse
and to apply efficiently to handle genomics data. While handling the genomics data (especially feature matrix obtained from RNA-seq and ChIP-seq) on a day to day basis using several functions from tidyverse
in R
, I realized that one needs to write some code, again and again, to prepare the data for final plot. To overcome this, I wrote an R package TidyWrappers
which help users to deal with object tbl
, which is the core data structure behind tidyverse
tools. TidyWrappers provides handy wrapper functions on top of dplyr
verbs to get
, count
, convert
, keep
, remove
and replace
data from a tbl
object. It contains more than 35 functions grouped into 8 different categories.
- tbl_convert_*
- tbl_count_vars_*
- tbl_get_vars_*
- tbl_keep_rows_*
- tbl_keep_vars_*
- tbl_remove_rows_*
- tbl_remove_vars_*
- tbl_replace_*
You can find TidyWrappers
here
Here, I want your inputs/comments/criticisms/suggestions to improve TidyWrappers
.
Here are some tricks from TidyWrappers
which saves little from writing a bit of code.
tbl <- tibble::tibble(a = letters[1:6], b = NA_character_, x = c(0,1,2,0,0,NA) , y = c(0,1,2,0,3,5) , z = c(0,1,2,0,3,5) )
tbl
## keep rows having 0 across all numeric columns.
# using dplyr
tbl %>% dplyr::filter_if(is.numeric , dplyr::all_vars( . == 0) )
# using TidyWrappers
tbl %>% TidyWrappers::tbl_keep_rows_zero_all()
## remove rows having 0 across all numeric columns.
# using dplyr
tbl %>% dplyr::filter_if(is.numeric , dplyr::any_vars( . > 0) )
# using TidyWrappers
tbl %>% TidyWrappers::tbl_remove_rows_zero_all()
## Convert log2 to all numeric columns optionally adding numeric fraction to original values.
# using dplyr
tbl %>% dplyr::mutate_if(is.numeric , ~ log2 (. + 1))
# using TidyWrappers
tbl %>% TidyWrappers::tbl_convert_log2(frac = 1)
## Remove columns / variables having atleaset one NA
# using dplyr
tbl %>% dplyr::select_if( ~ ( (is.na(.)) %>% any(., na.rm = T) %>% `!`) )
# using TidyWrappers
tbl %>% TidyWrappers::tbl_remove_vars_NA_any()
## Remove columns / variables having all values are NA
# using dplyr
tbl %>% dplyr::select_if( ~ ( (is.na(.)) %>% all(., na.rm = T) %>% `!`) )
# using TidyWrappers
tbl %>% TidyWrappers::tbl_remove_vars_NA_all()