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
0 answers

How could I use regex / stringr to dynamically see which R packages are used in a GitHub repo?

Suppose I have several R scripts within a GitHub repository, and I'd like to know which packages I've used (loaded) within all of the scripts. How could I accomplish this dynamically with the stringr package? As an example, I'd like to find package…
Dan Kalleward
  • 183
  • 1
  • 8
1
vote
3 answers

Problems in a regular expression to extract names using stringr

I cannot fully understand why my regular expression does not work to extract the info I want. I have an unlisted vector that looks like this: text <- c("Senator, 1.4balbal", "rule 46.1, declares", "Town, 24", "A Town with a Long…
1
vote
1 answer

Convert HTML Entity to proper character R

Does anyone know of a generic function in r that can convert ä to its unicode character â? I have seen some functions that take in â, and convert it to a normal character. Any help would be appreciated. Thanks. Edit: Below is a record of data,…
petergensler
  • 342
  • 2
  • 8
  • 23
1
vote
1 answer

How to surround a string with a box of X's in R?

This is the task: write a function that prints out a boxed sentence as follows: s<-"This is a sentence with different word lengths" box(s) prints the following" XXXXXXXXXXXXX X this X X is X X a X X sentence X X with X X…
1
vote
2 answers

Change strings with 'YYYYMMDD' to 'MMM YYYY' using R stringr

I have a character vector of strings my_strings where some elements include a single date in YYYYMMDD format. I'd like to replace the YYYYMMDD dates with MMM YYYY dates. For example, my_strings <- c('apple','2000 20150101 bar', '20160228') would…
lowndrul
  • 3,715
  • 7
  • 36
  • 54
1
vote
1 answer

Insert special character in R based on existing words

I was looking for a intuitive solution for a problem of mine. I have a huge list of words, in which i have to insert a special character based on some criteria. So if a two/three letter word appear in a cell i want to add "+" right and left to it…
PSraj
  • 229
  • 4
  • 10
1
vote
1 answer

Matching coordinates with different sign in R

I'm scraping a web map by downloading its html code and I want to extract coordinates of some points by matching regular expressions. I achieved extract the majority of coordinates with the following code: library(stringr) …
fcochaux
  • 135
  • 1
  • 13
1
vote
1 answer

Text Extraction in R with stringi package

I have the text below and need to extract specific words before and after a particular word Example: sometext <- "about us, close, products & services, focus, close, research & development, topics, carbon fiber reinforced thermoplastic, separators…
PRAVEEN R
  • 33
  • 1
  • 4
1
vote
2 answers

Extract only words containing ASCII characters from vector of strings

I'm stuck with it, so, please, any advice is welcome. b <- str_extract_all(c('hello ringпрг','trust'), regex("[a-z]+", TRUE)) Returns a list: List of 2 $ : chr [1:2] "hello" "ring" $ : chr "trust" But I want to have a vector with strings of…
Shin
  • 251
  • 1
  • 3
  • 8
1
vote
3 answers

Find pattern in URL with stringr and regex

I have a dataframe df with some urls. There are subcategories within the slashes in the URLs I want to extract with stringr and str_extract My data looks like Text URL Hello www.facebook.com/group1/bla/exy/1234 Test …
rkuebler
  • 95
  • 1
  • 11
1
vote
4 answers

String Splitting and Truncating using Regular Expressions in R

I am looking for help implementing a function in R to truncate a level_stream string vector of my dataframe in R and haven't had much luck yet. Essentially when a row in the pre_quiz_score column is not NA, I want to truncate the beginning part of…
1
vote
2 answers

tidytext example filter error with pipes

When trying to reproduce the example found in http://tidytextmining.com/twitter.html there's a problem. Basically I want to adapt this part of the code library(tidytext) library(stringr) reg <-…
Oki
  • 13
  • 4
1
vote
1 answer

How can I replace part of a string if it is included in a pattern

I am looking for a way to replace all _ (by say '') in each of the following characters x <- c('test_(match)','test_xMatchToo','test_a','test_b') if and only if _ is followed by ( or x. So the output wanted is: x <-…
statquant
  • 13,672
  • 21
  • 91
  • 162
1
vote
3 answers

How to delete a space between a number and a character using r and stringr

I am using R and stringr to do some string replacement. My text is like "xxxxxx xxxx xxxxxx 1.5L xxxxx" or "xxxxxx xxxx xxxxxx 1.5 L xxxxx". My question is: how to delete the space between 1.5 and L? or How to add a space between them?
Feng Chen
  • 2,139
  • 4
  • 33
  • 62
1
vote
2 answers

Sort and concatenate values by group

I've got a list of Groups and Names, as seen in DF below. I'm looking to arrange this list alphabetically and concatenate each name separated by a comma, as seen in DF2 below. I thought this would be simple, but it is proving to be more…
kputschko
  • 766
  • 1
  • 7
  • 21