I have the following sentence:
It is tricky for authors to figure out which keys will work, and how their values will be specified. Lamentably, it may be necessary to read the source code of an R package like rmarkdown to understand all of the details. However, usually, there is some relief in the fact that there is one example working document to exemplify the settings for a particular back end and authors can adjust and modify those values. The key:value pairs may may a difference at several stages in the compilation process.
I have tried to have all the text in a vector.
What I have done is put it all in a vector. As follows:
x<-c("It is tricky for authors to figure out which keys will work, and how their values will be specified. Lamentably, it may be necessary to read the source code of an R package like rmarkdown to understand all of the details. However, usually, there is some relief in the fact that there is one example working document to exemplify the settings for a particular back end and authors can adjust and modify those values. The key:value pairs may may a difference at several stages in the compilation process.")
I then used the strsplit function to split each word, as follows:
palabras<-strsplit(x, "\\s")
What I get:
[1] "It" "is" "tricky" "for" "authors" "to" "figure" "out"
[9] "which" "keys" "will" "work," "and" "how" "their" "values"
[17] "will" "be" "specified." "Lamentably," "it" "may" "be" "necessary"
[25] "to" "read" "the" "source" "code" "of" "an" "R"
[33] "package" "like" "rmarkdown" "to" "understand" "all" "of" "the"
[41] "details." "However," "usually," "there" "is" "some" "relief" "in"
[49] "the" "fact" "that" "there" "is" "one" "example" "working"
[57] "document" "to" "exemplify" "the" "settings" "for" "a" "particular"
[65] "back" "end" "and" "authors" "can" "adjust" "and" "modify"
[73] "those" "values." "The" "key:value" "pairs" "may" "may" "a"
[81] "difference" "at" "several" "stages" "in" "the" "compilation" "process."
But I don't know how from there to convert all those words into a vector.
That is to say to have a vector of 88 elements.
I don't know what else to do...
Is there any function that allows me to solve this problem easily?
It effectively
strsplit()
returns a list, but in this case with a single element, which is a character vector. If you want, you can directly extract that first element:Or you could also use
unlist()
:Why does it return a list? simply because it is capable of processing a vector with multiple elements, in your case there is only one:
For this case where there are multiple source elements, the extraction by
[[
should be done for each element of the list, on the contraryunlist()
in this case it returns a single complete vector