[Rd] NULL assignment will change the expression's class into list
Hello Everyone! NULL replacement will change expression object into list: > > te <- expression(a=23*4, b=33-2) > te expression(a = 23 * 4, b = 33 - 2) > te[["a"]] <- quote(blabla) #ok > te expression(a = blabla, b = 33 - 2) > te[["a"]] <- NULL #change to list > te $b 33 - 2 I am on w32, version 2.11.1 (2010-05-31) Regards, Vitally. [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] NULL assignment will change the expression's class into list
Vitalie Spinu wrote: Hello Everyone! NULL replacement will change expression object into list: te <- expression(a=23*4, b=33-2) te expression(a = 23 * 4, b = 33 - 2) te[["a"]] <- quote(blabla) #ok te expression(a = blabla, b = 33 - 2) te[["a"]] <- NULL #change to list te $b 33 - 2 I am on w32, version 2.11.1 (2010-05-31) That's certainly an inconsistency, still present in a recent R-devel (but I haven't checked the latest beta). I don't know if it's a bug: NULL assignments are handled specially in other situations (e.g. if te was a list to start, the NULL assignment would remove the "a" entry). A simple workaround is to use te["a"] <- expression(NULL) or te <- te[-1] instead, depending on what you expected to happen. Duncan Murdoch Regards, Vitally. [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] NULL assignment will change the expression's class into list
On Fri, Oct 8, 2010 at 12:14 PM, Duncan Murdoch wrote: > Vitalie Spinu wrote: > >> Hello Everyone! >> >> NULL replacement will change expression object into list: >> >> >> >>> te <- expression(a=23*4, b=33-2) >>> te >>> >>> >> expression(a = 23 * 4, b = 33 - 2) >> >> >> >>> te[["a"]] <- quote(blabla) #ok >>> te >>> >>> >> expression(a = blabla, b = 33 - 2) >> >> >> >>> te[["a"]] <- NULL #change to list >>> te >>> >>> >> $b >> 33 - 2 >> >> I am on w32, version 2.11.1 (2010-05-31) >> >> > > That's certainly an inconsistency, still present in a recent R-devel (but I > haven't checked the latest beta). I don't know if it's a bug: NULL > assignments are handled specially in other situations (e.g. if te was a list > to start, the NULL assignment would remove the "a" entry). > > A simple workaround is to use > > te["a"] <- expression(NULL) > > or te <- te[-1] > > instead, depending on what you expected to happen. > As ussual with NULL assignment in recursive structures, I would expect to remove the elements altogether. And this is exactly what I need. I would say it's a bug, because NULL assignment in data.frames would not convert them to lists, for example. Thanks for looking into it. It's quite inconvenient when you have to manipulate named expression. Have to use constructs like et<-et[!names(et)%in%"a"]. Vitally. > > Duncan Murdoch > > Regards, >> Vitally. >> >>[[alternative HTML version deleted]] >> >> __ >> R-devel@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel >> >> > > [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] NULL assignment will change the expression's class into list
On 08/10/2010 12:24 PM, Vitalie Spinu wrote: On Fri, Oct 8, 2010 at 12:14 PM, Duncan Murdochwrote: > Vitalie Spinu wrote: > >> Hello Everyone! >> >> NULL replacement will change expression object into list: >> >> >> >>> te<- expression(a=23*4, b=33-2) >>> te >>> >>> >> expression(a = 23 * 4, b = 33 - 2) >> >> >> >>> te[["a"]]<- quote(blabla) #ok >>> te >>> >>> >> expression(a = blabla, b = 33 - 2) >> >> >> >>> te[["a"]]<- NULL #change to list >>> te >>> >>> >> $b >> 33 - 2 >> >> I am on w32, version 2.11.1 (2010-05-31) >> >> > > That's certainly an inconsistency, still present in a recent R-devel (but I > haven't checked the latest beta). I don't know if it's a bug: NULL > assignments are handled specially in other situations (e.g. if te was a list > to start, the NULL assignment would remove the "a" entry). > > A simple workaround is to use > > te["a"]<- expression(NULL) > > or te<- te[-1] > > instead, depending on what you expected to happen. > As ussual with NULL assignment in recursive structures, I would expect to remove the elements altogether. And this is exactly what I need. I would say it's a bug, because NULL assignment in data.frames would not convert them to lists, for example. I think you're probably right. Thanks for looking into it. It's quite inconvenient when you have to manipulate named expression. Have to use constructs like et<-et[!names(et)%in%"a"]. Or simply follow te["a"] <- NULL with te <- as.expression(te) This is a pretty fast operation if te is an expression or a list formed by mistaken conversion from one. Duncan Murdoch Vitally. > > Duncan Murdoch > > Regards, >> Vitally. >> >> [[alternative HTML version deleted]] >> >> __ >> R-devel@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel >> >> > > __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] NULL assignment will change the expression's class into list
On Fri, Oct 8, 2010 at 7:49 PM, Duncan Murdoch wrote: > On 08/10/2010 12:24 PM, Vitalie Spinu wrote: > >> On Fri, Oct 8, 2010 at 12:14 PM, Duncan Murdoch> >wrote: >> >> > Vitalie Spinu wrote: >> > >> >> Hello Everyone! >> >> >> >> NULL replacement will change expression object into list: >> >> >> >> >> >> >> >>> te<- expression(a=23*4, b=33-2) >> >>> te >> >>> >> >>> >> >> expression(a = 23 * 4, b = 33 - 2) >> >> >> >> >> >> >> >>> te[["a"]]<- quote(blabla) #ok >> >>> te >> >>> >> >>> >> >> expression(a = blabla, b = 33 - 2) >> >> >> >> >> >> >> >>> te[["a"]]<- NULL #change to list >> >>> te >> >>> >> >>> >> >> $b >> >> 33 - 2 >> >> >> >> I am on w32, version 2.11.1 (2010-05-31) >> >> >> >> >> > >> > That's certainly an inconsistency, still present in a recent R-devel >> (but I >> > haven't checked the latest beta). I don't know if it's a bug: NULL >> > assignments are handled specially in other situations (e.g. if te was a >> list >> > to start, the NULL assignment would remove the "a" entry). >> > >> > A simple workaround is to use >> > >> > te["a"]<- expression(NULL) >> > >> > or te<- te[-1] >> > >> > instead, depending on what you expected to happen. >> > >> >> As ussual with NULL assignment in recursive structures, I would expect to >> remove the elements altogether. And this is exactly what I need. >> >> I would say it's a bug, because NULL assignment in data.frames would not >> convert them to lists, for example. >> > > I think you're probably right. > > Thanks for looking into it. It's quite inconvenient when you have to >> manipulate named expression. Have to use constructs like >> et<-et[!names(et)%in%"a"]. >> > > Or simply follow te["a"] <- NULL > > with > > te <- as.expression(te) > > This is a pretty fast operation if te is an expression or a list formed by > mistaken conversion from one. > > D But is this a reliable way to do it? I have been struggling some time ago with this type of conversion. Can not thing of an example now. But as far as I could remember, the conversion to list of an expression is not always reversible with as.expression. Am I wrong? > uncan Murdoch > > > Vitally. >> >> > >> > Duncan Murdoch >> > >> > Regards, >> >> Vitally. >> >> >> >> [[alternative HTML version deleted]] >> >> >> >> __ >> >> R-devel@r-project.org mailing list >> >> https://stat.ethz.ch/mailman/listinfo/r-devel >> >> >> >> >> > >> > >> >> > [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] NULL assignment will change the expression's class into list
Vitalie Spinu wrote: On Fri, Oct 8, 2010 at 7:49 PM, Duncan Murdoch wrote: On 08/10/2010 12:24 PM, Vitalie Spinu wrote: On Fri, Oct 8, 2010 at 12:14 PM, Duncan Murdoch wrote: Vitalie Spinu wrote: Hello Everyone! NULL replacement will change expression object into list: te<- expression(a=23*4, b=33-2) te expression(a = 23 * 4, b = 33 - 2) te[["a"]]<- quote(blabla) #ok te expression(a = blabla, b = 33 - 2) te[["a"]]<- NULL #change to list te $b 33 - 2 I am on w32, version 2.11.1 (2010-05-31) That's certainly an inconsistency, still present in a recent R-devel (but I haven't checked the latest beta). I don't know if it's a bug: NULL assignments are handled specially in other situations (e.g. if te was a list to start, the NULL assignment would remove the "a" entry). A simple workaround is to use te["a"]<- expression(NULL) or te<- te[-1] instead, depending on what you expected to happen. As ussual with NULL assignment in recursive structures, I would expect to remove the elements altogether. And this is exactly what I need. I would say it's a bug, because NULL assignment in data.frames would not convert them to lists, for example. I think you're probably right. Thanks for looking into it. It's quite inconvenient when you have to manipulate named expression. Have to use constructs like et<-et[!names(et)%in%"a"]. Or simply follow te["a"] <- NULL with te <- as.expression(te) This is a pretty fast operation if te is an expression or a list formed by mistaken conversion from one. D But is this a reliable way to do it? I have been struggling some time ago with this type of conversion. Can not thing of an example now. But as far as I could remember, the conversion to list of an expression is not always reversible with as.expression. Am I wrong? I don't know of any examples, but this is your construction. I think it's very unlikely this will be fixed for 2.12.0, but it will probably be fixed for 2.12.1, if 1. There is a 2.12.1 and 2. It really isn't intentional behaviour. Duncan Murdoch uncan Murdoch Vitally. Duncan Murdoch Regards, Vitally. [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel