dataURL <- "https://raw.githubusercontent.com/fivethirtyeight/data/master/college-majors/majors-list.csv"
majors <- read.csv(url(dataURL))
majors <- majors$Major
majors[1:11]
## [1] "GENERAL AGRICULTURE"
## [2] "AGRICULTURE PRODUCTION AND MANAGEMENT"
## [3] "AGRICULTURAL ECONOMICS"
## [4] "ANIMAL SCIENCES"
## [5] "FOOD SCIENCE"
## [6] "PLANT SCIENCE AND AGRONOMY"
## [7] "SOIL SCIENCE"
## [8] "MISCELLANEOUS AGRICULTURE"
## [9] "FORESTRY"
## [10] "NATURAL RESOURCES MANAGEMENT"
## [11] "FINE ARTS"
majors[str_detect(majors, "DATA|STATISTICS")]
## [1] "MANAGEMENT INFORMATION SYSTEMS AND STATISTICS"
## [2] "COMPUTER PROGRAMMING AND DATA PROCESSING"
## [3] "STATISTICS AND DECISION SCIENCE"
fruitvec <- c("bell pepper", "bilberry", "blackberry", "blood orange",
"blueberry", "cantaloupe", "chili pepper", "cloudberry",
"elderberry", "lime", "lychee", "mulberry", "olive",
"salal berry")
fruitvec
## [1] "bell pepper" "bilberry" "blackberry" "blood orange" "blueberry"
## [6] "cantaloupe" "chili pepper" "cloudberry" "elderberry" "lime"
## [11] "lychee" "mulberry" "olive" "salal berry"
fruitvec:strfruitvec <- str_flatten(fruitvec, collapse = '", "')
cat(c('c("', strfruitvec, '")'), sep = '')
## c("bell pepper", "bilberry", "blackberry", "blood orange", "blueberry", "cantaloupe", "chili pepper", "cloudberry", "elderberry", "lime", "lychee", "mulberry", "olive", "salal berry")
cat function produces the desired output format, but in order to produce an actual object that is a string and includes double quotes around each item, I don’t know if that’s possible, without backslashes appearing in the object.stringy_vec <- function(charvec) {
flat <- str_flatten(charvec, collapse = '", "')
cat(c('c("', flat, '")'), sep = '')
}
cheeses <- c('gouda', 'brie', 'stilton', 'american', 'string cheese')
stringy_vec(cheeses)
## c("gouda", "brie", "stilton", "american", "string cheese")
(.)\1\1"(.)(.)\\2\\1"(..)\1"(.).\\1.\\1""(.)(.)(.).*\\3\\2\\1""\\b(.)\\S*\\1\\b" allows internal numbers and symbols, so it"\\b.*([a-zA-Z][a-zA-Z])[a-zA-Z-]*\\1[a-zA-Z]*\\b" allows only letters,"\\b[a-zA-Z]*([a-zA-Z])[a-zA-Z]+\\1[a-zA-Z]+\\1[a-zA-Z]*\\b"…