[R] using temporary arrays in R

Gabor Grothendieck ggrothendieck at gmail.com
Mon Sep 3 16:18:31 CEST 2007


You can do it in a local, in a function or explicitly remove it.  Also
if you never assign it to a variable then it will be garbage collected as well

# 1
local({
	print(gc())
	x <- matrix(NA, 1000, 1000)
	print(gc())
})
gc()

# 2
f <- function() {
	print(gc())
	x <- matrix(NA, 1000, 1000)
	print(gc())
}
f()
gc()

# 3
gc()
x <- matrix(NA, 1000, 1000)
gc()
rm(x)
gc()

# 4
gc()
sum(matrix(1, 1000, 1000))
gc()



On 9/3/07, dxc13 <dxc13 at health.state.ny.us> wrote:
>
> useR's,
>
> Is there a way to create a temporary array (or matrix) in R to hold values,
> then drop or delete that temporary array from memory once I do not need it
> anymore?
>
> I am working with multidimensional arrays/matrices and I frequently perform
> multiple operations on the same matrix and rename it to be another object.
> I want to be able to delete the older versions of the array/matrix to free
> up space.
>
> Thank you.
> --
> View this message in context: http://www.nabble.com/using-temporary-arrays-in-R-tf4372367.html#a12462219
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list