Hello, I am wondering if it is possible to view what variables and vairable values are stored in the R memory. This to enable debugging of R-scripts I write. Sumit [[alternative HTML version deleted]]
>>>>> <Sumit.Gupta at ubs.com> >>>>> on Wed, 12 Sep 2007 03:01:43 +0100 writes:> Hello, I am wondering if it is possible to view what > variables and vairable values are stored in the R > memory. This to enable debugging of R-scripts I write. In simple to moderately small examples, I'd recommend (my own creation) ls.str() I've lately started to use it also from inside a function, i.e. after using debug(.) or after options(error = recover) and a jump "inside a function" to explore the local variables of the function I'm debugging. In that case, I use ls.str(envir = environment()) something which I've been using so frequently lately, that I had started wondering a bit if some nice (short and simple!) enhancement to ls.str() was possible which would make ls.str() {without specifying 'envir = environment()'} automagically use the "proper" environment when run inside a function. Since then, I had never found the time to follow the idea, we now have a quiz: What's the best solution to the above problem? Martin
the function ls() will list all the variables currently in the memory. To get their values, you'll also need to use the parse and eval functions. Try the following: x = ls() for(i in 1:length(x)){ print(x[i]) print(eval(parse(text=x[i]))) } It's a little crude, but it will do the job. Sam On 9/11/07, Sumit.Gupta at ubs.com <Sumit.Gupta at ubs.com> wrote:> Hello, > > I am wondering if it is possible to view what variables and vairable > values are stored in the R memory. This to enable debugging of R-scripts > I write. > > Sumit > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
You probably should be inserting browser() calls into your function instead -- once there you can list and examine all variables at whatever state your function is in. (and debugging is specifically what browser() was designed for). See ?browser() Bert Gunter Genentech Nonclinical Statistics -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Sumit.Gupta at ubs.com Sent: Tuesday, September 11, 2007 7:02 PM To: r-help at r-project.org Subject: [R] R: to view the memory Hello, I am wondering if it is possible to view what variables and vairable values are stored in the R memory. This to enable debugging of R-scripts I write. Sumit [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.