What is the best way to read this type of character vector?
"global warming" OR "carbon sink" OR biodiversity OR conservation OR "global change"
and transform it to
"global warming" OR "carbon sink" OR biodiversity OR conservation OR "global change"
CodePudding user response:
Do you want something like:
s <- '"global warming" OR "carbon sink" OR biodiversity OR conservation OR "global change"'
cat(gsub(" ", " ", s))
#"global warming" OR "carbon sink" OR biodiversity OR conservation OR "global change"
Without "
.
cat(gsub('"', "", gsub(" ", " ", s)))
#global warming OR carbon sink OR biodiversity OR conservation OR global change
CodePudding user response:
Is that what you want ?
text <- c("global warming" , "OR" , "carbon sink" , "OR" , "biodiversity" , "OR" , "conservation" , "OR" , "global change")
gsub(" " , " " , do.call(paste , as.list(text)))
CodePudding user response:
Assuming your string is read from a file /tmp/test
you could try something like this:
st = readLines('/tmp/test')
gsub('\\s ', ' ', gsub('\\\\|\\"', '', st))