Doug Fir
Doug Fir

Reputation: 21322

Can you access a variable that is within a function if it's not a global by doing something like functionname.someVar?

I'm working through an R tutorial. Currently I'm writing a script that, in it's current format I know is incorrect.

I'd like to "see" the variables I've created within the function within the console so that I can learn about them. I know that writing global variables is discouraged.

So if I have a function foo and within foo is a variable called someVar is there a way, once I've loaded in the script with the function to, for example go like this:

str(foo.someVar) or str(foo(somevar)) ?

Upvotes: 0

Views: 57

Answers (1)

merlin2011
merlin2011

Reputation: 75649

No, but if you want to walk through a function, you can use debugonce(functioname) before calling a function to break into a debugger when a function is called and you can then view variables internal to the function inside the debugger.

See here for more debugging tools in R.

Upvotes: 2

Related Questions