Dear all, Is there a way we can find the total object.size of all the objects in our R script? The reason we want to do this because we want to know how much memory does our R script require overall. Rprofmem(), doesn't seem to do it. and Unix 'top' command is dynamic and it doesn't give the exact byte size. - Gundala Viswanath Jakarta - Indonesia
Summary of Total Object.Size in R Script
7 messages · Gundala Viswanath, jim holtman, Brian Ripley +1 more
Here is a function I use to see how big the objects in my workspace are:
my.ls <-
+ function (pos = 1, sorted = F)
+ {
+ .result <- sapply(ls(pos = pos, all.names = TRUE), function(..x)
object.size(eval(as.symbol(..x))))
+ if (sorted) {
+ .result <- rev(sort(.result))
+ }
+ .ls <- as.data.frame(rbind(as.matrix(.result), `**Total` = sum(.result)))
+ names(.ls) <- "Size"
+ .ls$Size <- formatC(.ls$Size, big.mark = ",", digits = 0,
+ format = "f")
+ .ls$Mode <- c(unlist(lapply(rownames(.ls)[-nrow(.ls)],
function(x) mode(eval(as.symbol(x))))),
+ "-------")
+ .ls
+ }
my.ls()
Size Mode .my.env 28 environment .Random.seed 2,528 numeric .required 72 character my.ls 6,712 function **Total 9,340 -------
On Tue, Jan 13, 2009 at 9:53 AM, Gundala Viswanath <gundalav at gmail.com> wrote:
Dear all, Is there a way we can find the total object.size of all the objects in our R script? The reason we want to do this because we want to know how much memory does our R script require overall. Rprofmem(), doesn't seem to do it. and Unix 'top' command is dynamic and it doesn't give the exact byte size. - Gundala Viswanath Jakarta - Indonesia
______________________________________________ R-help at r-project.org 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.
Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
On Tue, 13 Jan 2009, jim holtman wrote:
Here is a function I use to see how big the objects in my workspace are:
Be careful with the caveats spelled out in ?object.size. Especially for character data such summations can be way off.
my.ls <-
+ function (pos = 1, sorted = F)
+ {
+ .result <- sapply(ls(pos = pos, all.names = TRUE), function(..x)
object.size(eval(as.symbol(..x))))
+ if (sorted) {
+ .result <- rev(sort(.result))
+ }
+ .ls <- as.data.frame(rbind(as.matrix(.result), `**Total` = sum(.result)))
+ names(.ls) <- "Size"
+ .ls$Size <- formatC(.ls$Size, big.mark = ",", digits = 0,
+ format = "f")
+ .ls$Mode <- c(unlist(lapply(rownames(.ls)[-nrow(.ls)],
function(x) mode(eval(as.symbol(x))))),
+ "-------")
+ .ls
+ }
my.ls()
Size Mode .my.env 28 environment .Random.seed 2,528 numeric .required 72 character my.ls 6,712 function **Total 9,340 ------- On Tue, Jan 13, 2009 at 9:53 AM, Gundala Viswanath <gundalav at gmail.com> wrote:
Dear all, Is there a way we can find the total object.size of all the objects in our R script? The reason we want to do this because we want to know how much memory does our R script require overall. Rprofmem(), doesn't seem to do it. and Unix 'top' command is dynamic and it doesn't give the exact byte size. - Gundala Viswanath Jakarta - Indonesia
______________________________________________ R-help at r-project.org 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.
-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
______________________________________________ R-help at r-project.org 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.
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
That is certainly true because I have seen differences due to the sharing of values. I also look at what 'gc()' shows at the memory being used. Does this provide a reasonable estimate of the total space being used? On Tue, Jan 13, 2009 at 11:14 AM, Prof Brian Ripley
<ripley at stats.ox.ac.uk> wrote:
On Tue, 13 Jan 2009, jim holtman wrote:
Here is a function I use to see how big the objects in my workspace are:
Be careful with the caveats spelled out in ?object.size. Especially for character data such summations can be way off.
my.ls <-
+ function (pos = 1, sorted = F)
+ {
+ .result <- sapply(ls(pos = pos, all.names = TRUE), function(..x)
object.size(eval(as.symbol(..x))))
+ if (sorted) {
+ .result <- rev(sort(.result))
+ }
+ .ls <- as.data.frame(rbind(as.matrix(.result), `**Total` =
sum(.result)))
+ names(.ls) <- "Size"
+ .ls$Size <- formatC(.ls$Size, big.mark = ",", digits = 0,
+ format = "f")
+ .ls$Mode <- c(unlist(lapply(rownames(.ls)[-nrow(.ls)],
function(x) mode(eval(as.symbol(x))))),
+ "-------")
+ .ls
+ }
my.ls()
Size Mode
.my.env 28 environment
.Random.seed 2,528 numeric
.required 72 character
my.ls 6,712 function
**Total 9,340 -------
On Tue, Jan 13, 2009 at 9:53 AM, Gundala Viswanath <gundalav at gmail.com>
wrote:
Dear all, Is there a way we can find the total object.size of all the objects in our R script? The reason we want to do this because we want to know how much memory does our R script require overall. Rprofmem(), doesn't seem to do it. and Unix 'top' command is dynamic and it doesn't give the exact byte size. - Gundala Viswanath Jakarta - Indonesia
______________________________________________ R-help at r-project.org 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.
-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
______________________________________________ R-help at r-project.org 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.
-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
On Tue, 13 Jan 2009, jim holtman wrote:
That is certainly true because I have seen differences due to the sharing of values. I also look at what 'gc()' shows at the memory being used. Does this provide a reasonable estimate of the total space being used?
Yes, but not just by your workspace, also all the loaded packages.
On Tue, Jan 13, 2009 at 11:14 AM, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
On Tue, 13 Jan 2009, jim holtman wrote:
Here is a function I use to see how big the objects in my workspace are:
Be careful with the caveats spelled out in ?object.size. Especially for character data such summations can be way off.
my.ls <-
+ function (pos = 1, sorted = F)
+ {
+ .result <- sapply(ls(pos = pos, all.names = TRUE), function(..x)
object.size(eval(as.symbol(..x))))
+ if (sorted) {
+ .result <- rev(sort(.result))
+ }
+ .ls <- as.data.frame(rbind(as.matrix(.result), `**Total` =
sum(.result)))
+ names(.ls) <- "Size"
+ .ls$Size <- formatC(.ls$Size, big.mark = ",", digits = 0,
+ format = "f")
+ .ls$Mode <- c(unlist(lapply(rownames(.ls)[-nrow(.ls)],
function(x) mode(eval(as.symbol(x))))),
+ "-------")
+ .ls
+ }
my.ls()
Size Mode
.my.env 28 environment
.Random.seed 2,528 numeric
.required 72 character
my.ls 6,712 function
**Total 9,340 -------
On Tue, Jan 13, 2009 at 9:53 AM, Gundala Viswanath <gundalav at gmail.com>
wrote:
Dear all, Is there a way we can find the total object.size of all the objects in our R script? The reason we want to do this because we want to know how much memory does our R script require overall. Rprofmem(), doesn't seem to do it. and Unix 'top' command is dynamic and it doesn't give the exact byte size. - Gundala Viswanath Jakarta - Indonesia
______________________________________________ R-help at r-project.org 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.
-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
______________________________________________ R-help at r-project.org 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.
-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
1 day later
Sorry for my late reply. Thank you so much Jim. This script of yours is very2 useful. I have used it. - Gundala Viswanath Jakarta - Indonesia
On Wed, Jan 14, 2009 at 12:17 AM, jim holtman <jholtman at gmail.com> wrote:
Here is a function I use to see how big the objects in my workspace are:
my.ls <-
+ function (pos = 1, sorted = F)
+ {
+ .result <- sapply(ls(pos = pos, all.names = TRUE), function(..x)
object.size(eval(as.symbol(..x))))
+ if (sorted) {
+ .result <- rev(sort(.result))
+ }
+ .ls <- as.data.frame(rbind(as.matrix(.result), `**Total` = sum(.result)))
+ names(.ls) <- "Size"
+ .ls$Size <- formatC(.ls$Size, big.mark = ",", digits = 0,
+ format = "f")
+ .ls$Mode <- c(unlist(lapply(rownames(.ls)[-nrow(.ls)],
function(x) mode(eval(as.symbol(x))))),
+ "-------")
+ .ls
+ }
my.ls()
Size Mode .my.env 28 environment .Random.seed 2,528 numeric .required 72 character my.ls 6,712 function **Total 9,340 ------- On Tue, Jan 13, 2009 at 9:53 AM, Gundala Viswanath <gundalav at gmail.com> wrote:
Dear all, Is there a way we can find the total object.size of all the objects in our R script? The reason we want to do this because we want to know how much memory does our R script require overall. Rprofmem(), doesn't seem to do it. and Unix 'top' command is dynamic and it doesn't give the exact byte size. - Gundala Viswanath Jakarta - Indonesia
______________________________________________ R-help at r-project.org 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.
-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
See also ll() in the R.oo package, e.g.
# To list all objects in .GlobalEnv:
ll()
member data.class dimension objectSize
1 *tmp* Person 1 428
2 as.character.Person function NULL 1208
3 country character 1 44
4 equals.Person function NULL 2324
5 filename character 1 84
6 getAge function NULL 372
7 getAge.Person function NULL 612
8 getName.Person function NULL 628
9 hashCode.Person function NULL 1196
10 last.warning list 1 192
11 obj Person 1 428
12 Person Class NULL 2292
13 setAge function NULL 372
14 setAge.Person function NULL 2088
15 setName function NULL 372
16 setName.Person function NULL 760
17 staticCode.Person function NULL 2372
# To list all functions in the methods package:
ll(mode="function", envir="methods")
# To list all numeric and character object in the base package:
ll(mode=c("numeric", "character"), envir="base")
# To list all objects in the base package greater than 40kb:
subset(ll(envir="base"), objectSize > 40000)
ll() takes argument 'properties', which allows you to construct any
column property you ever like. There is also a 'sortBy' argument.
See help(ll) for more details.
/Henrik
On Thu, Jan 15, 2009 at 3:00 AM, Gundala Viswanath <gundalav at gmail.com> wrote:
Sorry for my late reply. Thank you so much Jim. This script of yours is very2 useful. I have used it. - Gundala Viswanath Jakarta - Indonesia On Wed, Jan 14, 2009 at 12:17 AM, jim holtman <jholtman at gmail.com> wrote:
Here is a function I use to see how big the objects in my workspace are:
my.ls <-
+ function (pos = 1, sorted = F)
+ {
+ .result <- sapply(ls(pos = pos, all.names = TRUE), function(..x)
object.size(eval(as.symbol(..x))))
+ if (sorted) {
+ .result <- rev(sort(.result))
+ }
+ .ls <- as.data.frame(rbind(as.matrix(.result), `**Total` = sum(.result)))
+ names(.ls) <- "Size"
+ .ls$Size <- formatC(.ls$Size, big.mark = ",", digits = 0,
+ format = "f")
+ .ls$Mode <- c(unlist(lapply(rownames(.ls)[-nrow(.ls)],
function(x) mode(eval(as.symbol(x))))),
+ "-------")
+ .ls
+ }
my.ls()
Size Mode .my.env 28 environment .Random.seed 2,528 numeric .required 72 character my.ls 6,712 function **Total 9,340 ------- On Tue, Jan 13, 2009 at 9:53 AM, Gundala Viswanath <gundalav at gmail.com> wrote:
Dear all, Is there a way we can find the total object.size of all the objects in our R script? The reason we want to do this because we want to know how much memory does our R script require overall. Rprofmem(), doesn't seem to do it. and Unix 'top' command is dynamic and it doesn't give the exact byte size. - Gundala Viswanath Jakarta - Indonesia
______________________________________________ R-help at r-project.org 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.
-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
______________________________________________ R-help at r-project.org 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.