diff --git a/DESCRIPTION b/DESCRIPTION index 7e5d705..0e93435 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,36 +1,40 @@ Package: forstringr -Title: String Manipulation Package for Those Familiar with 'Microsoft Excel' +Title: String Manipulation Package for Those Familiar with 'Microsoft + Excel' Version: 0.1.1 Authors@R: c( - person("Ezekiel", "Ogundepo", , email = "gbganalyst@gmail.com", role = c("aut", "cre"), + person("Ezekiel", "Ogundepo", , "gbganalyst@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-3974-2733")), - person("Olubukunola", "Oyedele", , email = "olubukunola.oyedele@54gene.com", role = c("ctb")), - person("Fatimo", "Adebanjo", , email = "adebanjofatimo2000@gmail.com", role = c("ctb"))) -Description: The goal of 'forstringr' is to enable complex string manipulation in R - especially to those more familiar with LEFT(), RIGHT(), and MID() functions in - Microsoft Excel. The package combines the power of 'stringr' with other - manipulation packages such as 'dplyr' and 'tidyr'. + person("Olubukunola", "Oyedele", , "olubukunola.oyedele@54gene.com", role = "ctb"), + person("Fatimo", "Adebanjo", , "adebanjofatimo2000@gmail.com", role = "ctb") + ) Maintainer: Ezekiel Ogundepo -Repository: GitHub +Description: The goal of 'forstringr' is to enable complex string + manipulation in R especially to those more familiar with LEFT(), + RIGHT(), and MID() functions in Microsoft Excel. The package combines + the power of 'stringr' with other manipulation packages such as + 'dplyr' and 'tidyr'. License: MIT + file LICENSE -Encoding: UTF-8 URL: https://github.com/gbganalyst/forstringr BugReports: https://github.com/gbganalyst/forstringr/issues -Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 -Suggests: - knitr, - rmarkdown, - testthat (>= 3.0.0) -VignetteBuilder: knitr +Depends: + R (>= 2.10) Imports: dplyr, - ggplot2, glue, rlang, stringr, tidyselect +Suggests: + ggplot2, + knitr, + rmarkdown, + testthat (>= 3.0.0) +VignetteBuilder: + knitr Config/testthat/edition: 3 -Depends: - R (>= 2.10) +Encoding: UTF-8 LazyData: true +Repository: GitHub +Roxygen: list(markdown = TRUE) +RoxygenNote: 7.2.3 diff --git a/NAMESPACE b/NAMESPACE index c783ce3..e91a50c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -12,9 +12,5 @@ import(rlang) importFrom(dplyr,"%>%") importFrom(dplyr,across) importFrom(dplyr,mutate) -importFrom(ggplot2,aes) -importFrom(ggplot2,geom_histogram) -importFrom(ggplot2,ggplot) -importFrom(ggplot2,labs) importFrom(glue,glue) importFrom(stats,na.omit) diff --git a/R/str_englue.R b/R/str_englue.R index f11a7ba..4d4450b 100644 --- a/R/str_englue.R +++ b/R/str_englue.R @@ -2,12 +2,9 @@ #' @description #' `str_englue()` helps you solve the labeling problem during plotting. For example, any value wrapped in `{ }` will be inserted into the string and it can also understands embracing, `{{ }}`, which automatically inserts a given variable name. # Suppress R CMD check note for glue package (not use but imported for rland) -#' @importFrom glue glue +#' #' @inheritParams rlang::englue -#' @importFrom ggplot2 ggplot -#' @importFrom ggplot2 aes -#' @importFrom ggplot2 geom_histogram -#' @importFrom ggplot2 labs +#' @importFrom glue glue #' @import rlang #' #' @seealso @@ -16,14 +13,18 @@ #' @export #' #' @examples +#' \donttest{ +#' library(ggplot2) +#' #' histogram_plot <- function(df, var, binwidth) { -#' df |> -#' ggplot(aes(x = {{ var }})) + +#' ggplot(df, aes(x = {{ var }})) + #' geom_histogram(binwidth = binwidth) + #' labs(title = str_englue("A histogram of {{var}} with binwidth {binwidth}")) -#'} - -#' iris |> histogram_plot(Sepal.Length, binwidth = 0.1) - +#' } +#' +#' histogram_plot(iris, Sepal.Length, binwidth = 0.1) +#' } +#' str_englue <- function(x, env, error_call, error_arg) englue(x, env = caller_env(), error_call = current_env(), error_arg = "x") + diff --git a/README.Rmd b/README.Rmd index dfd39ae..29d6a86 100644 --- a/README.Rmd +++ b/README.Rmd @@ -23,6 +23,8 @@ knitr::opts_chunk$set( [![metacran downloads](https://cranlogs.r-pkg.org/badges/grand-total/forstringr)](https://cran.r-project.org/package=forstringr) +## Overview + The string (or character) data type typically requires more manipulation to be helpful for data analysts. Thus, there is a need for a robust package that is up to the task. **forstringr** is a new package built on top of 'stringr' to execute various string manipulations in R programming. The main aim of 'forstringr' is to simplify string manipulation for R beginners. This package combines its power with the adaptability of other manipulation tools such as tidyr and dplyr. Like in the stringr package, most functions in `forstringr` begin with `str_`. For a quick video tutorial, I gave a talk at Africa R users meetup, which you can find [here](https://r4africa.org/event/1sept2022). @@ -45,6 +47,27 @@ if(!require("devtools")){ devtools::install_github("gbganalyst/forstringr") ``` +## Usage + +This section provides a concise overview of the different functions available in the `forstringr` package. These functions serve various purposes and are designed to aid in string manipulation tasks. + +- [`length_omit_na()`](#length_omit_na) + +- [`str_left()`](#str_left) + +- [`str_right()`](#str_right) + +- [`str_mid()`](#str_mid) + +- [`str_split_extract()`](#str_split_extract) + +- [`str_extract_part()`](#str_extract_part) + +- [`str_englue()`](#str_englue) + +- [`str_rm_whitespace_df()`](#str-rm-whitespace-df) + + ## `length_omit_na()` `length_omitna()` counts only non-missing elements of a vector. @@ -59,7 +82,7 @@ length(ethnicity) # Count all the observations, including the NAs. length_omit_na(ethnicity) ``` -## `str_left()` +## `str_left()` Given a character vector, `str_left()` returns the left side of a string. For examples: @@ -72,7 +95,7 @@ str_left("Nigeria", n = 3) str_left(c("Female", "Male", "Male", "Female")) ``` -## `str_right()` +## `str_right()` Given a character vector, `str_right()` returns the right side of a string. For examples: @@ -83,7 +106,7 @@ str_right("July 20, 2022", 4) str_right("Sale Price", n = 5) ``` -## `str_mid()` +## `str_mid()` Like in Microsoft Excel, the `str_mid()`returns a specific number of characters from a text string, starting at the position you specify, based on the number of characters you select. @@ -93,7 +116,7 @@ str_mid("Super Eagle", 7, 5) str_mid("Oyo Ibadan", 5, 6) ``` -## `str_split_extract()` +## `str_split_extract()` If you want to split up a string into pieces and extract the results using a specific index position, then, you will use `str_split_extract()`. You can interpret it as follows: @@ -107,7 +130,7 @@ first_name <- str_split_extract(top_10_richest_nig, " ", 1) first_name ``` -## `str_extract_part()` +## `str_extract_part()` Extract strings before or after a given pattern. For example: @@ -121,7 +144,7 @@ revenue <- c("$159", "$587", "$891", "$207", "$793") str_extract_part(revenue, pattern = "$", before = FALSE) ``` -## `str_englue()` +## `str_englue()` You can dynamically label ggplot2 plots with the glue operators `[` or `{{}}` using `str_englue()`. For example, any value wrapped in `{ }` will be inserted into the string and you automatically inserts a given variable name using `{{ }}`. diff --git a/README.md b/README.md index c60a358..f39c3e2 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ downloads](https://cranlogs.r-pkg.org/badges/grand-total/forstringr)](https://cran.r-project.org/package=forstringr) +## Overview + The string (or character) data type typically requires more manipulation to be helpful for data analysts. Thus, there is a need for a robust package that is up to the task. **forstringr** is a new package built on @@ -41,6 +43,28 @@ if(!require("devtools")){ devtools::install_github("gbganalyst/forstringr") ``` +## Usage + +This section provides a concise overview of the different functions +available in the `forstringr` package. These functions serve various +purposes and are designed to aid in string manipulation tasks. + +- [`length_omit_na()`](#length_omit_na) + +- [`str_left()`](#str_left) + +- [`str_right()`](#str_right) + +- [`str_mid()`](#str_mid) + +- [`str_split_extract()`](#str_split_extract) + +- [`str_extract_part()`](#str_extract_part) + +- [`str_englue()`](#str_englue) + +- [`str_rm_whitespace_df()`](#str-rm-whitespace-df) + ## `length_omit_na()` `length_omitna()` counts only non-missing elements of a vector. diff --git a/Rplot.png b/Rplot.png deleted file mode 100644 index 540032b..0000000 Binary files a/Rplot.png and /dev/null differ diff --git a/man/str_englue.Rd b/man/str_englue.Rd index c1e43fd..12ef751 100644 --- a/man/str_englue.Rd +++ b/man/str_englue.Rd @@ -25,13 +25,18 @@ origin of a problem.} \code{str_englue()} helps you solve the labeling problem during plotting. For example, any value wrapped in \code{{ }} will be inserted into the string and it can also understands embracing, \code{{{ }}}, which automatically inserts a given variable name. } \examples{ +\donttest{ +library(ggplot2) + histogram_plot <- function(df, var, binwidth) { - df |> - ggplot(aes(x = {{ var }})) + + ggplot(df, aes(x = {{ var }})) + geom_histogram(binwidth = binwidth) + labs(title = str_englue("A histogram of {{var}} with binwidth {binwidth}")) } -iris |> histogram_plot(Sepal.Length, binwidth = 0.1) + +histogram_plot(iris, Sepal.Length, binwidth = 0.1) +} + } \seealso{ \code{\link[rlang:englue]{rlang::englue()}} diff --git a/tests/testthat/test-test-str_englue.R b/tests/testthat/test-str_englue.R similarity index 100% rename from tests/testthat/test-test-str_englue.R rename to tests/testthat/test-str_englue.R