Skip to content

Commit

Permalink
Merge pull request #19 from ThinkR-open/startupmessage
Browse files Browse the repository at this point in the history
Create a startup message displaying thinkr
  • Loading branch information
statnmap authored Aug 12, 2022
2 parents 30f581e + 0a69c91 commit c11eb16
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 37 deletions.
26 changes: 11 additions & 15 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]",
comment = c(ORCID = "0000-0003-0671-9270")),
person(given = "Sébastien",
family = "Rochette",
role = "aut",
email = "[email protected]",
comment = c(ORCID = "0000-0002-1565-9313")),
person(given = "ThinkR",
role = "cph"))
Authors@R: c(
person("Vincent", "Guyader", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-0671-9270")),
person("Sébastien", "Rochette", , "[email protected]", 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
Expand All @@ -27,6 +21,7 @@ Depends:
R (>= 3.1)
Imports:
assertthat,
cli,
devtools,
dplyr,
ggplot2,
Expand All @@ -40,7 +35,8 @@ Imports:
stringi,
stringr,
tidyr,
utils
utils,
withr
Suggests:
knitr,
rmarkdown,
Expand All @@ -49,4 +45,4 @@ VignetteBuilder:
knitr
Encoding: UTF-8
LazyData: TRUE
RoxygenNote: 7.1.1
RoxygenNote: 7.1.2
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -51,3 +52,4 @@ importFrom(stringr,str_detect)
importFrom(tidyr,unite)
importFrom(utils,browseURL)
importFrom(utils,write.csv2)
importFrom(withr,with_preserve_seed)
39 changes: 38 additions & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
globalVariables(c(".","Var2","Var1"))
globalVariables(c(".", "Var2", "Var1"))

#' ThinkR welcome message
#'
#' @return a package startup message
#' @importFrom withr with_preserve_seed
#' @noRd
.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")
}
37 changes: 30 additions & 7 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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_*`
Expand All @@ -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, ...
Expand All @@ -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
Expand Down
39 changes: 31 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!-- badges: start -->

[![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)
Expand Down Expand Up @@ -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`
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -165,15 +186,17 @@ 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
#> 3 4.7 3.2 1.3 0.2 setosa
#> 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
Expand All @@ -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
```

Expand Down
7 changes: 1 addition & 6 deletions man/thinkr-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions tests/testthat/test-startupmessage.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
test_that("Startup message is ok", {
expect_equal(
capture_output_lines(startupmessage()),
c(
" ################################################################# ",
" ############################# #################################### ",
"#### # ### ####### #### ## ### ## ####",
"######### ##### ### ## ## ### ## ## #### ## ####",
"######## ##### ## ## # # ## ##### ######",
"####### ##### ### ## ## ### ## ## #### ## ######",
"###### ##### ### ## ## #### ## #### ## #### #####",
" #################################################################### ",
" ################################################################## "
)
)
})

0 comments on commit c11eb16

Please sign in to comment.