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