Skip to content

Commit

Permalink
Remove stringb dependency (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudgallou authored Nov 27, 2023
1 parent aadc9ec commit 1a16e63
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 188 deletions.
7 changes: 2 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ Type: Package
Package: plume
Title: A Simple Author Handler for Scientific Writing
Version: 0.1.0.9000
Authors@R: c(
Authors@R:
person("Arnaud", "Gallou", , "[email protected]", role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0002-1002-4247")),
person("Hadley", "Wickham", role = "cph",
comment = "Author of included stringb functions.")
)
comment = c(ORCID = "0000-0002-1002-4247"))
Description: Handles and formats author information in scientific writing
in 'R Markdown' and 'Quarto'. 'plume' provides easy-to-use and
flexible tools for injecting author metadata in 'YAML' headers as well
Expand Down
27 changes: 0 additions & 27 deletions LICENSE.note

This file was deleted.

8 changes: 8 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ importFrom(rlang,is_true)
importFrom(rlang,set_names)
importFrom(rlang,sym)
importFrom(rlang,syms)
importFrom(stringr,fixed)
importFrom(stringr,regex)
importFrom(stringr,str_extract)
importFrom(stringr,str_extract_all)
importFrom(stringr,str_remove_all)
importFrom(stringr,str_replace)
importFrom(stringr,str_replace_all)
importFrom(stringr,str_split_1)
importFrom(tibble,as_tibble)
importFrom(tibble,as_tibble_row)
importFrom(tibble,rowid_to_column)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# plume (development version)

* Removed stringb dependency in favour of stringr (#42).

* The `by` parameter in `$set_*()` methods is now deprecated in favour of `.by` (#41).

* `Plume` gains a new method `$set_main_contributors()` that allows you to force one or more contributors to appear first in the contribution list for any given role. `Plume`'s contructor also regains the parameter `by` to set the default `by`/`.by` value used in all `set_*()` methods.
Expand Down
10 changes: 5 additions & 5 deletions R/als.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ als_key_set <- function(format) {
}

als_extract_keys <- function(x) {
x <- string_split(x)
x <- str_split_1(x, "")
x[x %in% letters]
}

als_extract_mark <- function(format, key) {
mark_regex <- paste0("[,^]{1,2}(?=", key, ")")
mark <- string_extract(format, mark_regex)
mark <- str_extract(format, mark_regex)
if (is.na(mark)) {
return("")
}
mark
}

als_sanitise <- function(x) {
string_remove_all(x, "([,^])\\K\\1+")
str_remove_all(x, "(?<=([,^]))\\1+")
}

als_parse <- function(format) {
Expand All @@ -40,7 +40,7 @@ als_parse <- function(format) {

als_join <- function(elts, marks) {
out <- map2_vec(elts, marks, \(elt, mark) {
if (is_blank(elt) & string_contain(mark, "^")) {
if (is_blank(elt) & str_contain(mark, "^")) {
return("^")
} else if (is_blank(elt)) {
return(elt)
Expand All @@ -52,7 +52,7 @@ als_join <- function(elts, marks) {

als_clean <- function(x) {
for (pattern in c("(?<=^|\\^),|,$", "\\^{2}")) {
x <- string_remove_all(x, pattern)
x <- str_remove_all(x, pattern)
}
x
}
Expand Down
20 changes: 10 additions & 10 deletions R/checkers.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
has_uppercase <- function(x) {
string_detect(x, "\\p{Lu}")
str_detect(x, "\\p{Lu}")
}

detect_name <- function(x, name) {
string_detect(names(x), name)
str_detect(names(x), name)
}

has_name <- function(x, name) {
Expand All @@ -14,20 +14,20 @@ has_name.default <- function(x, name) {
name %in% names(x)
}

has_name.regex <- function(x, name) {
has_name.stringr_regex <- function(x, name) {
any(detect_name(x, name))
}

has_metachr <- function(x) {
string_detect(x, r"{[\\\[\](){}|?$^*+]}")
str_detect(x, r"{[\\\[\](){}|?$^*+]}")
}

has_homonyms <- function(x) {
vec_duplicate_any(names(x))
}

has_overflowing_ws <- function(x) {
string_detect(x, "^\\s|\\s$")
str_detect(x, "^\\s|\\s$")
}

is_empty <- function(x) {
Expand Down Expand Up @@ -55,7 +55,7 @@ is_nested <- function(x, item) {
}

is_blank <- function(x) {
string_detect(x, "^\\s*$")
str_detect(x, "^\\s*$")
}

is_not_na <- Negate(is.na)
Expand Down Expand Up @@ -258,7 +258,7 @@ check_suffix_format <- function(x, allowed, arg = caller_arg(x)) {
}

path_is_relative <- function(x) {
!string_detect(x, "^(/|[A-Za-z]:|\\\\|~)")
!str_detect(x, "^(/|[A-Za-z]:|\\\\|~)")
}

check_path <- function(x, ..., arg = caller_arg(x)) {
Expand All @@ -274,7 +274,7 @@ check_path <- function(x, ..., arg = caller_arg(x)) {
}

file_ext <- function(x) {
string_extract(x, "(?<=\\.)[^.]+$")
str_extract(x, "(?<=\\.)[^.]+$")
}

check_file <- function(x, extension, ..., arg = caller_arg(x)) {
Expand All @@ -289,7 +289,7 @@ check_file <- function(x, extension, ..., arg = caller_arg(x)) {
}

is_glueish <- function(x) {
is_string(x) && string_detect(x, "{[^}]+}")
is_string(x) && str_detect(x, "\\{[^}]+\\}")
}

check_glue <- function(x, allowed, ..., arg = caller_arg(x)) {
Expand All @@ -310,7 +310,7 @@ check_glue <- function(x, allowed, ..., arg = caller_arg(x)) {
}

is_orcid <- function(x) {
string_detect(x, "^(?:\\d{4}-){3}\\d{3}(?:\\d|X)$")
str_detect(x, "^(?:\\d{4}-){3}\\d{3}(?:\\d|X)$")
}

check_orcid <- function(x, ..., arg = caller_arg(x)) {
Expand Down
5 changes: 3 additions & 2 deletions R/credit_roles.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ credit_roles <- function(oxford_spelling = TRUE) {
}

full_rename <- function(x, pattern, replacement) {
names(x) <- string_replace(names(x), pattern, replacement)
string_replace(x, pattern, replacement)
names(x) <- str_replace(names(x), pattern, replacement)
x[] <- str_replace(x, pattern, replacement)
x
}
2 changes: 1 addition & 1 deletion R/plume-handler.R
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ PlumeHandler$set("private", "check_role_system", function() {
return()
}
roles <- select(private$plume, starts_with(var))
have_explicit_roles <- map_vec(roles, \(role) any(string_detect(role, "\\D")))
have_explicit_roles <- map_vec(roles, \(role) any(str_detect(role, "\\D")))
if (!all(have_explicit_roles)) {
return()
}
Expand Down
2 changes: 2 additions & 0 deletions R/plume-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#' @importFrom rlang caller_env caller_arg
#' @importFrom glue glue glue_collapse
#' @importFrom vctrs vec_group_id vec_duplicate_any vec_restore vec_rank
#' @importFrom stringr str_split_1 str_remove_all str_replace str_replace_all
#' @importFrom stringr str_extract str_extract_all fixed regex
#' @importFrom jsonlite toJSON parse_json
#' @importFrom yaml yaml.load as.yaml
#' @importFrom R6 R6Class
Expand Down
6 changes: 3 additions & 3 deletions R/plume-quarto.R
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ parse_affiliation <- function(x) {
}
keys <- collapse(affiliation_keys, sep = "|")
keys_regex <- paste0("\\b(?i:", keys, ")")
nms <- string_extract_all(x, sprintf("%s(?==)", keys_regex))
els <- string_split(x, sprintf("\\s*%s=\\s*", keys_regex))[-1]
nms <- str_extract_all(x, sprintf("%s(?==)", keys_regex), simplify = TRUE)
els <- str_split_1(x, sprintf("\\s*%s=\\s*", keys_regex))[-1]
set_names(els, tolower(nms))
}

Expand All @@ -244,5 +244,5 @@ make_affiliation_id <- function(x) {
}

has_affiliation_sep <- function(x) {
string_contain(x, "=")
str_contain(x, "=")
}
121 changes: 0 additions & 121 deletions R/strings.R

This file was deleted.

Loading

0 comments on commit 1a16e63

Please sign in to comment.