1

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?

1 Answer 1

1

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")
2
  • Thanks so much! So I'm relatively new to R, does the unlist function literally just make a list not a list?
    – djc1223
    Jun 29, 2020 at 17:32
  • In this case you can think of the unlist function as pasting those two strings together as one long string. There is (technically) more to it than that but you can think of it this way. If my answer helped you then please click the check mark and accept it!
    – bstrain
    Jun 29, 2020 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.