I am using a function to gather data, reorganise it and write it into a SQL database. Over the execution I read in various data.tables and assign data to various objects and write these objects then back to the SQL database.
The only thing I actually return from the function is a small status update on how long the function was running and possible error messages.
agent start_time end_time duration_minutes success error_msg return_msg
1: R_Script.R 2019-11-18 15:35:32 2019-11-18 15:36:58 1.433333 TRUE Finished
I thought in R the environment of a function is just transitory, i.e. after execution the data used and accessed by the function is removed, nevertheless I do see that the object.size
of the function increases from 393248 bytes after the initial sourcing in an empty environment to 2618752 bytes after the execution. Using pryr::object_size()
the size of the function after execution is only reported to be 724kB and before execution 471kB.
The function works and all the data is stored on the file system via saveRDS
and written to a database using odbc
and DBI
. I am basically just curious on what is causing the increasing size of the function. I couldn't find an explanation in the documents describing the different environments, here http://adv-r.had.co.nz/Environments.html#function-envs