Skip to content

Commit

Permalink
Merge pull request #4 from gbganalyst/englue
Browse files Browse the repository at this point in the history
Worked on failed R cmd check
  • Loading branch information
gbganalyst authored Apr 11, 2023
2 parents af4bf64 + 0cb532b commit b62acea
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 44 deletions.
44 changes: 24 additions & 20 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 <gbganalyst@gmail.com>
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
4 changes: 0 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
23 changes: 12 additions & 11 deletions R/str_englue.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")


35 changes: 29 additions & 6 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<!-- badges: end -->

## 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).


Expand All @@ -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.
Expand All @@ -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:

Expand All @@ -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:

Expand All @@ -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.

Expand All @@ -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:

Expand All @@ -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:

Expand All @@ -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 `{{ }}`.

Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
downloads](https://cranlogs.r-pkg.org/badges/grand-total/forstringr)](https://cran.r-project.org/package=forstringr)
<!-- badges: end -->

## 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
Expand Down Expand Up @@ -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.
Expand Down
Binary file removed Rplot.png
Binary file not shown.
11 changes: 8 additions & 3 deletions man/str_englue.Rd

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

File renamed without changes.

0 comments on commit b62acea

Please sign in to comment.