Sunday 28 June 2015

R : dump : Dump objects to a file

“dump” function takes a vector of names of R objects and produces text representations of the objects on a file or connection.

Syntax
dump(list, file = "dumpdata.R", append = FALSE,
     control = "all", envir = parent.frame(), evaluate = TRUE)


Parameter
Description
list
It is a character vector, contains names of one/more objects to dump into file
file
It represents a file (or) a connection to dump objects
append
If append is true, then output is appended to file, else output overwrites the file.
control
Character vector indicates de-parsing options
envir
Environment to search for objects
evaluate
It is a Boolean variable, specifies whether promises be evaluated or not? Promise objects are part of R’s lazy evaluation mechanism.


> var1 <- 10
> var2 <- "1234"
> var3 <- 1:10
> 
> var1
[1] 10
> var2
[1] "1234"
> var3
 [1]  1  2  3  4  5  6  7  8  9 10
> 
> vector1 <- c("var1", "var2", "var3")
> vector1
[1] "var1" "var2" "var3"
> 
> dump(vector1, "dump.txt")
> 
> list.files()
[1] "dump.txt"     "employee.csv" "employee.txt" "myFunction.R" "output.txt"  

When I open “dump.txt”, it contains following information.

var1 <-
10
var2 <-
"1234"
var3 <-
1:10



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment