Ramiro Ferrando
Ramiro Ferrando

Reputation: 1

Combining strings in vector

first time posting. I hope you forgive any mistake I might make.

I have to get data from USA Today. After getting all the paragraphs, I'm kind of stuck because I need to put the 17 paragraphs into 1 piece of text so I can export to a .txt. Help would be much appreciated

USATodayURL <- 'https://www.usatoday.com/story/news/2018/04/05/youtube-shooter-legally-bought-handgun-reloaded-least-once-during-attack-police-say/490969002/'

text_USAToday <- 
  USATodayURL %>% 
  read_html() %>%
  html_nodes('.p-text') %>% 
  html_text()
text_USAToday

Upvotes: 0

Views: 39

Answers (1)

Martin Schmelzer
Martin Schmelzer

Reputation: 23899

Just use paste:

write(paste(text_USAToday, collapse="\n"), file = "usa.txt")

The argument collapse="\n" tells paste to insert a line break between the elements.

Upvotes: 1

Related Questions