Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
We at STATWORX work a lot with R and we often use the same little helper functions within our projects. These functions ease our daily work life by reducing repetitive code parts or by creating overviews of our projects. At first, there was no plan to make a package, but soon I realised, that it will be much easier to share and improve those functions, if they are within a package. Up till the 24th December I will present one function each day from helfRlein
. So, on the 9th day of Christmas my true love gave to me…
What can it do?
This little helper shows a table with the size of each object in the given environment.
If you are in a situation where you have coded a lot and your environment is now quite messy, object_size_in_env
helps you to find the big fish with respect to memory usage. Personally, I ran into this problem a few times when I looped over multiple executions of my models. At some point, the sessions became quite large in memory and I did not know why! With the help of object_size_in_env
and some degubbing I could locate the object that caused this problem and adjusted my code accordingly.
How to use it?
First, let us create an environment with some variables.
# building an environment this_env <- new.env() assign("Var1", 3, envir = this_env) assign("Var2", 1:1000, envir = this_env) assign("Var3", rep("test", 1000), envir = this_env)
To get the size information of our objects, internally format(object.size())
is used. With the unit
the output format can be changed (eg. "B"
, "MB"
or "GB"
) .
# checking the size object_size_in_env(env = this_env, unit = "B") OBJECT SIZE UNIT 1: Var3 8104 B 2: Var2 4048 B 3: Var1 56 B
Overview
To see all the other functions you can either check out our GitHub or you can read about them here.
Have a merry advent season!
Über den Autor
Jakob Gepp
ABOUT US
STATWORX
is a consulting company for data science, statistics, machine learning and artificial intelligence located in Frankfurt, Zurich and Vienna. Sign up for our NEWSLETTER and receive reads and treats from the world of data science and AI.
Der Beitrag Day 09 – little helper object_size_in_env erschien zuerst auf STATWORX.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.