0

Possible Duplicate:
Limiting variable scope

Is there a way to force R to ignore all objects set in the global environment? For example, let's say I have 'df' as an object outside of my function and I wish to use the same shorthand within my function, but not in reference to the object in the global environment

Community
  • 1
  • 1
Brandon Bertelsen
  • 43,807
  • 34
  • 160
  • 255

2 Answers2

2

See this question: "Limiting variable scope".

Community
  • 1
  • 1
Shane
  • 98,550
  • 35
  • 224
  • 217
2

So what? The df in your function won't be the global df.

> df = 1
> foo = function(x){df=x*2;return(df)}

Now when you do foo(df) the df inside the function isn't the global df. So what's your problem? I guess it can only be a problem if you want the global df inside your function as well, in which case:

  • don't use globals in functions - it breaks the functional style
  • use a different name if it's a different thing.
Spacedman
  • 92,590
  • 12
  • 140
  • 224