From 13dd783e519912b85a394847fc12e80e279d0115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Br=C3=A9ant?= Date: Fri, 11 Mar 2022 13:31:02 +0100 Subject: [PATCH 1/3] Create a startup message displaying thinkr --- DESCRIPTION | 23 +++++++++-------------- NAMESPACE | 1 + R/zzz.R | 30 +++++++++++++++++++++++++++++- man/thinkr-package.Rd | 7 +------ 4 files changed, 40 insertions(+), 21 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 34eec3c..c9652ed 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,19 +1,13 @@ Package: thinkr Title: Tools for Cleaning Up Messy Files Version: 0.15 -Authors@R: - c(person(given = "Vincent", - family = "Guyader", - role = c("aut", "cre"), - email = "vincent@thinkr.fr", - comment = c(ORCID = "0000-0003-0671-9270")), - person(given = "Sébastien", - family = "Rochette", - role = "aut", - email = "sebastien@thinkr.fr", - comment = c(ORCID = "0000-0002-1565-9313")), - person(given = "ThinkR", - role = "cph")) +Authors@R: c( + person("Vincent", "Guyader", , "vincent@thinkr.fr", role = c("aut", "cre"), + comment = c(ORCID = "0000-0003-0671-9270")), + person("Sébastien", "Rochette", , "sebastien@thinkr.fr", role = "aut", + comment = c(ORCID = "0000-0002-1565-9313")), + person("ThinkR", role = "cph") + ) Description: Some tools for cleaning up messy 'Excel' files to be suitable for R. People who have been working with 'Excel' for years built more or less complicated sheets with names, characters, formats that are @@ -27,6 +21,7 @@ Depends: R (>= 3.1) Imports: assertthat, + cli, devtools, dplyr, ggplot2, @@ -49,4 +44,4 @@ VignetteBuilder: knitr Encoding: UTF-8 LazyData: TRUE -RoxygenNote: 7.1.1 +RoxygenNote: 7.1.2 diff --git a/NAMESPACE b/NAMESPACE index 3aa7106..ffef74e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -32,6 +32,7 @@ importFrom(assertthat,is.date) importFrom(assertthat,is.dir) importFrom(assertthat,is.writeable) importFrom(assertthat,not_empty) +importFrom(cli,cat_line) importFrom(devtools,package_file) importFrom(dplyr,mutate_at) importFrom(ggplot2,ggsave) diff --git a/R/zzz.R b/R/zzz.R index 235acb4..1767aa2 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1 +1,29 @@ -globalVariables(c(".","Var2","Var1")) +globalVariables(c(".", "Var2", "Var1")) + +#' ThinkR welcome message +#' +#' @importFrom cli cat_line +#' +#' @return a package startup message +#' @noRd +#' +#' @examples .onAttach() +.onAttach <- function(libname, pkgname) { + packageStartupMessage( + cli::cat_line( +"###################################################################### +############################## ##################################### +#### # ### ####### #### ## ### ## #### +######### ##### ### ## ## ### ## ## #### ## #### +######## ##### ## ## # # ## ##### ######", + col = "#f05622" + ), + cli::cat_line( +"####### ##### ### ## ## ### ## ## #### ## ###### +###### ##### ### ## ## #### ## #### ## #### ##### +###################################################################### +######################################################################", + col = "#20b8d6" + ) + ) +} diff --git a/man/thinkr-package.Rd b/man/thinkr-package.Rd index 17c84e9..dffaccc 100644 --- a/man/thinkr-package.Rd +++ b/man/thinkr-package.Rd @@ -8,12 +8,7 @@ \description{ \if{html}{\figure{logo.png}{options: align='right' alt='logo' width='120'}} -Some tools for cleaning up messy 'Excel' files to be suitable - for R. People who have been working with 'Excel' for years built more - or less complicated sheets with names, characters, formats that are - not homogeneous. To be able to use them in R nowadays, we built a set - of functions that will avoid the majority of importation problems and - keep all the data at best. +Some tools for cleaning up messy 'Excel' files to be suitable for R. People who have been working with 'Excel' for years built more or less complicated sheets with names, characters, formats that are not homogeneous. To be able to use them in R nowadays, we built a set of functions that will avoid the majority of importation problems and keep all the data at best. } \seealso{ Useful links: From 6206d6d81cb0d7f22e9b5a6582a2235ffc652c6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Br=C3=A9ant?= Date: Fri, 11 Mar 2022 14:37:07 +0100 Subject: [PATCH 2/3] Add test for startup message --- R/zzz.R | 28 +++++++++++++--------------- tests/testthat/test-startupmessage.R | 16 ++++++++++++++++ 2 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 tests/testthat/test-startupmessage.R diff --git a/R/zzz.R b/R/zzz.R index 1767aa2..bbc99a1 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -10,20 +10,18 @@ globalVariables(c(".", "Var2", "Var1")) #' @examples .onAttach() .onAttach <- function(libname, pkgname) { packageStartupMessage( - cli::cat_line( -"###################################################################### -############################## ##################################### -#### # ### ####### #### ## ### ## #### -######### ##### ### ## ## ### ## ## #### ## #### -######## ##### ## ## # # ## ##### ######", - col = "#f05622" - ), - cli::cat_line( -"####### ##### ### ## ## ### ## ## #### ## ###### -###### ##### ### ## ## #### ## #### ## #### ##### -###################################################################### -######################################################################", - col = "#20b8d6" - ) + cat_line(c( + " ################################################################# ", + " ############################# #################################### ", + "#### # ### ####### #### ## ### ## ####", + "######### ##### ### ## ## ### ## ## #### ## ####", + "######## ##### ## ## # # ## ##### ######" + ), col = "#f05622"), + cat_line(c( + "####### ##### ### ## ## ### ## ## #### ## ######", + "###### ##### ### ## ## #### ## #### ## #### #####", + " #################################################################### ", + " ################################################################## " + ), col = "#20b8d6") ) } diff --git a/tests/testthat/test-startupmessage.R b/tests/testthat/test-startupmessage.R new file mode 100644 index 0000000..6ecb656 --- /dev/null +++ b/tests/testthat/test-startupmessage.R @@ -0,0 +1,16 @@ +test_that("Startup message is ok", { + expect_equal( + capture_output_lines(.onAttach()), + c( + " ################################################################# ", + " ############################# #################################### ", + "#### # ### ####### #### ## ### ## ####", + "######### ##### ### ## ## ### ## ## #### ## ####", + "######## ##### ## ## # # ## ##### ######", + "####### ##### ### ## ## ### ## ## #### ## ######", + "###### ##### ### ## ## #### ## #### ## #### #####", + " #################################################################### ", + " ################################################################## " + ) + ) +}) \ No newline at end of file From 0a69c91a593db6bcc7e5a60760dad89ec34bf06d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arthur=20Br=C3=A9ant?= Date: Fri, 1 Apr 2022 17:02:14 +0200 Subject: [PATCH 3/3] Show package startup message more rarely --- DESCRIPTION | 3 +- NAMESPACE | 1 + R/zzz.R | 51 +++++++++++++++++----------- README.Rmd | 37 ++++++++++++++++---- README.md | 39 ++++++++++++++++----- tests/testthat/test-startupmessage.R | 2 +- 6 files changed, 96 insertions(+), 37 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c9652ed..9acdb7b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -35,7 +35,8 @@ Imports: stringi, stringr, tidyr, - utils + utils, + withr Suggests: knitr, rmarkdown, diff --git a/NAMESPACE b/NAMESPACE index ffef74e..3b4d342 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -52,3 +52,4 @@ importFrom(stringr,str_detect) importFrom(tidyr,unite) importFrom(utils,browseURL) importFrom(utils,write.csv2) +importFrom(withr,with_preserve_seed) diff --git a/R/zzz.R b/R/zzz.R index bbc99a1..2a3367e 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -2,26 +2,37 @@ globalVariables(c(".", "Var2", "Var1")) #' ThinkR welcome message #' -#' @importFrom cli cat_line -#' #' @return a package startup message +#' @importFrom withr with_preserve_seed #' @noRd -#' -#' @examples .onAttach() -.onAttach <- function(libname, pkgname) { - packageStartupMessage( - cat_line(c( - " ################################################################# ", - " ############################# #################################### ", - "#### # ### ####### #### ## ### ## ####", - "######### ##### ### ## ## ### ## ## #### ## ####", - "######## ##### ## ## # # ## ##### ######" - ), col = "#f05622"), - cat_line(c( - "####### ##### ### ## ## ### ## ## #### ## ######", - "###### ##### ### ## ## #### ## #### ## #### #####", - " #################################################################### ", - " ################################################################## " - ), col = "#20b8d6") - ) +.onAttach <- function(...) { + withr::with_preserve_seed({ + if (!interactive() | stats::runif(1) > 0.02) { + return() + } + + packageStartupMessage(startupmessage()) + }) } + +#' ThinkR message +#' +#' @importFrom cli cat_line +#' +#' @return thinkr message +#' @noRd +startupmessage <- function() { + cat_line(c( + " ################################################################# ", + " ############################# #################################### ", + "#### # ### ####### #### ## ### ## ####", + "######### ##### ### ## ## ### ## ## #### ## ####", + "######## ##### ## ## # # ## ##### ######" + ), col = "#f05622") + cat_line(c( + "####### ##### ### ## ## ### ## ## #### ## ######", + "###### ##### ### ## ## #### ## #### ## #### #####", + " #################################################################### ", + " ################################################################## " + ), col = "#20b8d6") +} \ No newline at end of file diff --git a/README.Rmd b/README.Rmd index 3f338da..b6d3950 100644 --- a/README.Rmd +++ b/README.Rmd @@ -48,6 +48,18 @@ Github development version devtools::install_github("ThinkR-open/thinkr") ``` +Once installed, you can load `{thinkr}`: + +```{r} +library(thinkr) +``` + +or without the package startup message: + +```{r} +suppressPackageStartupMessages(library(thinkr)) +``` + ## Usage ### `peep` @@ -56,13 +68,22 @@ devtools::install_github("ThinkR-open/thinkr") ```{r} data(iris) # just symbols -iris %>% peep(head,tail) %>% rename(species = Species) %>% summary +iris %>% + peep(head, tail) %>% + rename(species = Species) %>% + summary() # expressions with . -iris %>% peep(head(., n = 2), tail(., n = 3) ) %>% summary +iris %>% + peep(head(., n = 2), tail(., n = 3)) %>% + summary() # or both -iris %>% peep(head, tail(., n = 3) ) %>% summary +iris %>% + peep(head, tail(., n = 3)) %>% + summary() # use verbose to see what happens -iris %>% peep(head,tail(., n = 3), verbose = TRUE) %>% summary +iris %>% + peep(head, tail(., n = 3), verbose = TRUE) %>% + summary() ``` ### `clean_*` @@ -72,8 +93,10 @@ Function `clean_names` allows to clean dirty names, while removing special chara ```{r} data(iris) -iris %>% head -iris %>% clean_names() %>% head +iris %>% head() +iris %>% + clean_names() %>% + head() ``` Function `clean_vec` allows to clean character vectors, while removing special characters, spaces, ... @@ -90,7 +113,7 @@ Find Excel column position name from column number and inversely ```{r} ncol_to_excel(6) -excel_to_ncol('AF') +excel_to_ncol("AF") ``` ## Code of Conduct diff --git a/README.md b/README.md index f85d472..c3d2e3d 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![R-CMD-check](https://github.com/ThinkR-open/thinkr/workflows/R-CMD-check/badge.svg)](https://github.com/ThinkR-open/thinkr/actions) -[![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/thinkr)](https://cran.r-project.org/package=thinkr) +[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/thinkr)](https://cran.r-project.org/package=thinkr) [![](http://cranlogs.r-pkg.org/badges/thinkr)](https://cran.r-project.org/package=thinkr) [![Coverage status](https://codecov.io/gh/ThinkR-open/thinkr/branch/master/graph/badge.svg)](https://codecov.io/github/ThinkR-open/thinkr?branch=master) @@ -37,6 +37,18 @@ Github development version devtools::install_github("ThinkR-open/thinkr") ``` +Once installed, you can load `{thinkr}`: + +``` r +library(thinkr) +``` + +or without the package startup message: + +``` r +suppressPackageStartupMessages(library(thinkr)) +``` + ## Usage ### `peep` @@ -47,7 +59,10 @@ devtools::install_github("ThinkR-open/thinkr") ``` r data(iris) # just symbols -iris %>% peep(head,tail) %>% rename(species = Species) %>% summary +iris %>% + peep(head, tail) %>% + rename(species = Species) %>% + summary() #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> 1 5.1 3.5 1.4 0.2 setosa #> 2 4.9 3.0 1.4 0.2 setosa @@ -77,7 +92,9 @@ iris %>% peep(head,tail) %>% rename(species = Species) %>% summary #> #> # expressions with . -iris %>% peep(head(., n = 2), tail(., n = 3) ) %>% summary +iris %>% + peep(head(., n = 2), tail(., n = 3)) %>% + summary() #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> 1 5.1 3.5 1.4 0.2 setosa #> 2 4.9 3.0 1.4 0.2 setosa @@ -100,7 +117,9 @@ iris %>% peep(head(., n = 2), tail(., n = 3) ) %>% summary #> #> # or both -iris %>% peep(head, tail(., n = 3) ) %>% summary +iris %>% + peep(head, tail(., n = 3)) %>% + summary() #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> 1 5.1 3.5 1.4 0.2 setosa #> 2 4.9 3.0 1.4 0.2 setosa @@ -127,7 +146,9 @@ iris %>% peep(head, tail(., n = 3) ) %>% summary #> #> # use verbose to see what happens -iris %>% peep(head,tail(., n = 3), verbose = TRUE) %>% summary +iris %>% + peep(head, tail(., n = 3), verbose = TRUE) %>% + summary() #> head(.) #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> 1 5.1 3.5 1.4 0.2 setosa @@ -165,7 +186,7 @@ special characters, spaces, … ``` r data(iris) -iris %>% head +iris %>% head() #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> 1 5.1 3.5 1.4 0.2 setosa #> 2 4.9 3.0 1.4 0.2 setosa @@ -173,7 +194,9 @@ iris %>% head #> 4 4.6 3.1 1.5 0.2 setosa #> 5 5.0 3.6 1.4 0.2 setosa #> 6 5.4 3.9 1.7 0.4 setosa -iris %>% clean_names() %>% head +iris %>% + clean_names() %>% + head() #> sepal_length sepal_width petal_length petal_width species #> 1 5.1 3.5 1.4 0.2 setosa #> 2 4.9 3.0 1.4 0.2 setosa @@ -200,7 +223,7 @@ Find Excel column position name from column number and inversely ``` r ncol_to_excel(6) #> [1] "F" -excel_to_ncol('AF') +excel_to_ncol("AF") #> [1] 32 ``` diff --git a/tests/testthat/test-startupmessage.R b/tests/testthat/test-startupmessage.R index 6ecb656..e6f76a6 100644 --- a/tests/testthat/test-startupmessage.R +++ b/tests/testthat/test-startupmessage.R @@ -1,6 +1,6 @@ test_that("Startup message is ok", { expect_equal( - capture_output_lines(.onAttach()), + capture_output_lines(startupmessage()), c( " ################################################################# ", " ############################# #################################### ",