Skip to content
Prev 363368 / 398503 Next

Antwort: Re: Accessing an object using a string

My example shows that using a dedicated environment allows you to segregate the items loaded from the save file from the objects you are working with. It has the advantage that any kind of object or collection of objects can be loaded that way. It has the disadvantage that you have to keep track of what kinds of objects they are (as in not data frames).

For example, suppose you want to make a data table that summarizes information about the contents of several save files. If you name the data frame you are building up "infodf" and one of the save files has a data frame by that name in it, then loading it into the global environment will wipe out the information so far accumulated and replace it with something else.

Greg's option of saving individual objects into rds files is another solution. It has the advantage of letting you control the name of the imported object, but you still need to independently insure that the object is actually a data frame somehow before digging into its columns.

Personally, I prefer to avoid keeping lots of rds or RData files around... I favor restarting from original input files to insure reproducibility. Any output values that I want to emit from my analysis I write into CSV or other portable format. I only use rds/RData files for temporary storage (caching) for performance acceleration.