Questions tagged [stringr]

The stringr package is a wrapper for the R stringi package that provides consistent function names and error handling for string manipulation. It is part of the Tidyverse collection of packages. Use this tag for questions involving the manipulation of strings specifically with the stringr package. For general R string manipulation questions use the R tag together with the generic string tag.

's stringr package provides a more consistent user interface to base-R's string manipulation and regular expression functions.

Repositories

Other resources

Related tags

2501 questions
1
vote
1 answer

R : str_replace_all function not converting "2010-12-31+10" to "2011-01-10"

I have a string like this: str1 <- "get all securities in portfolio port1 on date 2010-12-31 where field value of Close on 2010-12-31+10 less than 2000" I am trying to convert "2010-12-31+10" to "2011-01-10" in str1. I tried str_replace_all method…
Dinoop Nair
  • 2,663
  • 6
  • 31
  • 51
1
vote
4 answers

How to replace column in a dynamically-named data frame in R

I'm working on some stuff for my fantasy football league. I populate a series of data frames, each named for the position (e.g., QB for quarterbacks, RB for running backs, etc.) I've been able to use the apply() function to do a lot with rbinding…
Maashu
  • 305
  • 2
  • 10
1
vote
1 answer

An error I can't understand. "Promise already under evaluation..."

I am trying to write a function that finds pattern in names, with the help of stringr package. My function looks like following: namezz=function(thepatternx,data=data,column=Name){ library(stringr) thepattern=as.character(quote(thepatternx)) …
user1665355
  • 3,324
  • 8
  • 44
  • 84
1
vote
1 answer

How to match multiple capture groups with str_match(..., regex)

I am using str_match from the stringr package to capture text in between brackets. library(stringr) strs = c("P5P (abcde) + P5P (fghij)", "Glcext (abcdef)") str_match(strs, "\\(([a-z]+)\\)") gives me only the matches "abcde" and "abcdef". How can…
user1981275
  • 13,002
  • 8
  • 72
  • 101
1
vote
1 answer

Using regular expression to extract repeated phrase in R

I am attempting to locate(then extract) a repeated phrase by using the below code. I require phrases beginning with "approximately" and ending in "closed". For example "approximately $162.9 million in total assets and $144.5 million in total…
barryq
  • 185
  • 1
  • 1
  • 8
1
vote
4 answers

R count times word appears in element of list

I have a list comprised of words. > head(splitWords2) [[1]] [1] "Some" "additional" "information" "that" "we" "would" "need" "to" "replicate" "the" [11] "experiment" "is" "how" …
screechOwl
  • 27,310
  • 61
  • 158
  • 267
0
votes
1 answer

R String Match anywhere and replace

I have a vector of strings from a survey, and that vector has info about the job position of the people. Some of the replies are: ceo, Ceo, CEO, ceo/owner, ceo/founder. I want to replace any strings that contain the word ceo (upper case, lower case,…
Humberto R
  • 19
  • 4
0
votes
0 answers

Regex error: pattern exceeds limits on size or complexity

I have a dataframe of ~20,0000 observations, I am focused specifically on a column that has abstracts of scientific journals. I am attempting to pull plant species out of these abstracts. So I wanted to use this function to do so... find.all.matches…
0
votes
2 answers

Wrap long text categories on a ggplot axis

I want to wrap long category labels on my ggplot in R. I know I can use str_wrap() and scale_x_manual() to wrap them onto a new line after, say 10 words. However, several of my category labels are king strings of continuous characters, without…
Mike
  • 921
  • 7
  • 26
0
votes
1 answer

R dplyr replace strings with only spaces, for all columns

the key issue is i need it dynamic, as I many not know which columns are empty (especially if new ones are added). here is my current attempt based on code from here: singleAction <- tibble::tibble( datePublished = as.Date("2022/01/01"), title =…
Aaron C
  • 301
  • 1
  • 8
0
votes
2 answers

Extract a non-matching portion of a string using stringr and lookahead

I have a string which always contains unwanted text at the end. I would like to extract everything but the unwanted text. text <- "my_text_and_unwanted_text" output <- str_extract(text, ".*(?=<_and)") output I am hoping that ".*" matches all text…
marcel
  • 389
  • 1
  • 8
  • 21
0
votes
1 answer

Word Boundaries in R for Word Filtering

I am filtering some pathway names, and I want to include only pathways that contains: "HEMATOPOIETIC", "ERYTHROCYTE", "ERYTHROID", "STEM", "STEMNESS", "HEMATOPOIESIS" and make a bar plot of the results. This is my script so far: obese <- gsea_obese…
daddabi
  • 1
  • 1
0
votes
2 answers

How to use regex in str_replace (stringr) to rename variables in R

I'm using R 4.3.1 I have a data frame with several variables, including years. The years are formatted this way: X1960..YR1960. I would like to rename all the variables following this pattern to a simplified version: Y1960 The dataframe contains…
0
votes
2 answers

How to parse a JSON like structure for every row in a dataframe?

I am trying to parse a a column within my dataframe that resembles a JSON-like structure into a new dataframe. Although, when I run my code, it is only outputting the first row of the dataframe. How do I alter what I currently have so that it…
matt
  • 13
  • 3
0
votes
1 answer

Extract everything before second delimiter in R

Building off this previous post: How to extract string after 2nd delimiter in R Have a string like the following: "dat1/set1/set1_covars.csv" And want to extract all the values before the second / like: "dat1/set1/" I was using variations…
TDeramus
  • 77
  • 5
1 2 3
99
100