What is the inverse of scan () in R?

I just want to write a list of integers separated by spaces into a file in R. I can read a list separated by a space from a file using scan , but is there a function for the opposite? In other words, how can I write a vector of integers to a file so that I can scan file later to read the same vector in?

I don't want anything like save or write.table .

+6
file-io r
source share
2 answers

write does the job:

 x <- c(10.4, 5.6, 3.1, 6.4, 21.7) write (x, "mydata") # writes space separated list y <- scan("mydata") x == y # returns TRUE TRUE ... TRUE 
+6
source share

I think you want to provide an agrument file for cat() , which writes to a file without any additional functions.

 > cat(1:20,file="foobar.txt") > x <- scan("foobar.txt") Read 20 items > x [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 
+9
source share

All Articles