How to Export Text Lines to TXT File in R (Example Code)

In this tutorial, I’ll explain how to export text lines to an external TXT file in R.

Creation of Example Data

my_lines <- c("First Line",        # Exemplifying text lines in R
              "Second Line",
              "Third Line",
              "Fourth Line",
              "Fifth Line")
my_lines                           # Show text lines in RStudio
# [1] "First Line"  "Second Line" "Third Line"  "Fourth Line" "Fifth Line"

Example: Apply writeLines Function to Export Text Lines to TXT File

writeLines(my_lines,               # Export text lines as TXT document
           "output_file.txt")

Further Resources

Have a look at the following R programming tutorials. They focus on similar topics as this post.

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top