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

StackOverflow https://stackoverflow.com/questions/23689559

  •  23-07-2023
  •  | 
  •  

Question

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)) ?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top