Filesize .Rdata file console vs. terminal execution

If I create an R script script.R that has the following content:

x <- rep(1, 10000000)
save(x, file = "x.Rdata")

I can execute this script in two ways:

source("script.R") which saves a file that is approximately 73 MB large
system("Rscript script.R") which saves a file that is approximately 114 kb large

However, when loading the x.Rdata file it returns the correct object x for both methods.

In other words the terminal execution of the script somehow manages to save the same object but as a much smaller file. This also happens when saving large data frames [5GB in source, less than 1 GB in terminal].

I am curious if someone can explain what is actually happening here [probably something to do with compression], and perhaps more interestingly why this difference exists.

Thanks

what do you get for

options("save.defaults")

?

this

$save.defaults
$save.defaults$ascii
[1] FALSE

$save.defaults$compress
[1] FALSE

based on that we wouldnt expect save to compress in your current session (with direct sourcing) . Perhaps you set this in one of R's myriad user or site profiles....

You can alter it to default compress if you want that behaviour.

options(save.defaults=list(compress="gzip"))

will do it in your current session.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.