R scripts often exchange data through CSV files. A script can write a table, read it back, and clean up.

Program

Play the script to watch a temporary CSV become data and then a total.

csv_io.R
path <- tempfile(fileext = ".csv")
write.csv(data.frame(x = c(1, 2)), path, row.names = FALSE)
data <- read.csv(path)
total <- sum(data$x)
unlink(path)
cat(total, "\n", sep = "")
tempfile `tempfile` creates a path for short-lived data.
write.csv `write.csv` writes a data frame to a CSV file.
read.csv `read.csv` loads a CSV file into a data frame.