Skip to content
Prev 363356 / 398502 Next

Antwort: Re: Accessing an object using a string

Hi Greg 
and all others who replied to my question,

many thanks for all your answers and help. Currently I store all my 
objects in .GlobalEnv = Workspace. I am not yet familiar working with 
different environments nor did I see that this would be necessary for my 
analysis.

Could you explain why working with different environments would be 
helpful?

You suggested to read variables into lists rather than storing them in 
global variables. This sounds interesting. Could you provide an example of 
how to define and use this?

Kind regards

Georg



Von:    Greg Snow <538280 at gmail.com>
An:     G.Maubach at weinwolf.de, 
Kopie:  r-help <r-help at r-project.org>
Datum:  15.08.2016 20:33
Betreff:        Re: [R] Accessing an object using a string



The names function is a primitive, which means that if it does not
already do what you want, it is generally not going to be easy to
coerce it to do it.

However, the names of an object are generally stored as an attribute
of that object, which can be accessed using the attr or attributes
functions.  If you change your code to not use the names function and
instead use attr or attributes to access the names then it should work
for you.


You may also want to consider changing your workflow to have your data
objects read into a list rather than global variables, then process
using lapply/sapply (this would require a change in how your data is
saved from your example, but if you can change that then everything
after can be cleaner/simpler/easier/more fool proof/etc.)
On Mon, Aug 15, 2016 at 2:49 AM, <G.Maubach at weinwolf.de> wrote:
a
http://www.R-project.org/posting-guide.html