There is no substitute for experience/knowledge; nor any universally optimal strategy for debugging. But using the debugging tools that R provides -- ?debug, ?traceback, ?recover (e.g. in the form of options(error = utils::recover) ) -- should always be the first goto (or maybe the second after carefully re-reading relevant Help docs). However, the debugging tools would not have helped here afaics.
-- Bert On Tue, Dec 27, 2022 at 10:22 AM akshay kulkarni <akshay...@hotmail.com> wrote: > > Dear Bert, > Yeah, it's working....Sometimes (only sometimes) I feel > that I am troubling this list with very simple questions the answer to which > I always happen to find myself a little after...any solutions for that (you > seem to be an omniscient person)!? > > Thanking you, > Yours sincerely, > AKSHAY M KULKARNI > ________________________________ > From: Bert Gunter <bgunter.4...@gmail.com> > Sent: Tuesday, December 27, 2022 11:39 PM > To: akshay kulkarni <akshay...@hotmail.com> > Cc: Sarah Goslee <sarah.gos...@gmail.com>; R help Mailing list > <r-help@r-project.org> > Subject: Re: [R] error in exists..... > > You are confused about the list hierarchy. Perhaps this will explain: > > i <- 1 > > E <- new.env() > > E$L <- list() ## L is an empty list in E > > i <- 1 > > E$L[[i]]$T1A1 <- Sys.time() > Error in `*tmp*`[[i]] : subscript out of bounds > ## L is empty, so L[[1]] does not exist; is not a list; > ## cannot have a value assigned to a component > ## The following works: > ## Create an empty list as a sublist of L > > E$L[[1]] <- list() > ## Now create and assign to a component of the empty list > > E$L[[i]]$T1A1 <- Sys.time() > > E$L ## a list > [[1]] ## whose first component is a list > [[1]]$T1A1 ## T1A1 named component of L[[1]] > [1] "2022-12-27 10:00:10 PST" > > ergo, no conundra... (assuming I've understood you correctly) > > Cheers, > Bert > > On Tue, Dec 27, 2022 at 9:57 AM akshay kulkarni <akshay...@hotmail.com> wrote: > > > > Dear Sarah, > > I had this also before the assignment of Sys.time(): > > > > > E$L[[i]] <- i > > > > After assignment of Sys.time(): > > > > > E$L > > [[1]] > > [[1]][[1]] > > [1] 1 > > > > [[1]]$T1A1 > > [1] "2022-12-27 22:40:02 IST" > > > > regrets for not sharing this ......Can you reproduce it now? > > > > Thanking you, > > Yours sincerely, > > AKSHAY M KULKARNI > > ________________________________ > > From: Sarah Goslee <sarah.gos...@gmail.com> > > Sent: Tuesday, December 27, 2022 11:20 PM > > To: akshay kulkarni <akshay...@hotmail.com> > > Cc: R help Mailing list <r-help@r-project.org> > > Subject: Re: [R] error in exists..... > > > > Hi, > > > > I can't create the desired object using the code you provided, but if > > I create it in two steps so that E$L[[i]]$T1A1 does exist, exist() > > returns TRUE. > > > > E <- new.env() > > E$L <- list() > > i <- 1 > > E$L[[i]]$T1A1 <- Sys.time() > > > > # returns: Error in `*tmp*`[[i]] : subscript out of bounds > > > > E$L[[i]] <- list() > > E$L[[i]]$T1A1 <- Sys.time() > > > > > > exists("T1A1", where = E$L[[i]]) > > # returns: [1] TRUE > > > > > > > str(E$L) > > List of 1 > > $ :List of 1 > > ..$ T1A1: POSIXct[1:1], format: "2022-12-27 12:47:26" > > > > Sarah > > > > On Tue, Dec 27, 2022 at 12:36 PM akshay kulkarni <akshay...@hotmail.com> > > wrote: > > > > > > Dear members, > > > I have the following code: > > > > E <- new.env() > > > > E$L <- list() > > > > i <- 1 > > > > E$L[[i]]$T1A1 <- Sys.time() > > > > exists("T1A1", where = E$L[[i]]) > > > Error in list2env(list(1, T1A1 = 1672161002.38743), NULL, <environment>) : > > > attempt to use zero-length variable name > > > > > > I want the output of the exists() function to be TRUE. In any case: > > > > > > > E$L[[1]]$T1A1 > > > [1] "2022-12-27 22:40:02 IST" > > > > > > Please help me solve this conundrum.... > > > > > > Thanking you, > > > Yours sincerely, > > > AKSHAY M KULKARNI > > > > > > > > > [[alternative HTML version deleted]] > > > > > > ______________________________________________ > > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > > 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. > > > > > > > > -- > > Sarah Goslee (she/her) > > http://www.numberwright.com > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.