djc1223
djc1223

Reputation: 55

Writing a list into a txt file

I want to write a list of paragraphs into a txt file to view after manipulating them, the list is called psw_list and you can reference the first paragraph by using psw_list$p1. psw_list$p1 looks like:

> psw_list$p1
[1] "For more than five years, William Sencion did the same task over and over. He signed onto the New York City’s housing lottery site and applied for one of the city’s highly coveted, below-market apartments. Each time, he got the same response: silence."

Any ideas?

Upvotes: 1

Views: 219

Answers (1)

bstrain
bstrain

Reputation: 278

The write(...) function is what you are looking for. If you want to write all of the paragraphs to one file you need to use the unlist(...) function, as seen below.

These functions will dump the resulting .txts into your working directory.

psw_list <- c()
psw_list$p1 <- "For more than five years, William Sencion did the same task over and over. He signed onto the New York City’s housing lottery site and applied for one of the city’s highly coveted, below-market apartments. Each time, he got the same response: silence."
psw_list$p2 <- "Something something dark side. Luke I am your father."

write(psw_list$p1, "first_paragraph.txt")
write(unlist(psw_list), "all_pragraphs.txt")

Upvotes: 1

Related Questions