To export list to a file in R, you can use sink() function. Using this function we can create connection with file then using print() you can write list to file.

The following method shows how you can do it with syntax.

Method: Use sink() Function




The following example shows how to export list to file in R using sink() function.

Using sink() Function

Let’s see how we can use sink() function to export list to file in R:

# Create list
list_ <- list(Machine_name=c("A","B","C","D","E","F"),
                 Pressure=c(78.2, 71.7, 80.21, 83.12, 82.56, 79.50),
                 Temperature=c(31, 35, 36, 36, 38, 32))

# Define file name

# Print list to file

# Close connection to file 

Here the above code shows list is export to a sample.txt file. In the above code we pass file name to sink() function then print list to file. Finally close connection with file.