However, it seems to have broken the equivalence
between within.list and within.data.frame, so now
within.list <- within.data.frame
There have been many improvements since then, so maybe we can
change the code so that the above will work again.
Another problem seems that we had no tests of within.list()
anywhere... so we will have them now.
I've hade an idea that seems to work and even simplify the
code.... will get back to the issue later in the evening.
Martin
The crux of the matter seems to be that both the following
constructions work for data frames
aq <- head(airquality)
names(aq)
[1] "Ozone" "Solar.R" "Wind" "Temp" "Month" "Day"
aq[c("Wind","Temp")] <- NULL
aq
Ozone Solar.R Month Day
1 41 190 5 1
2 36 118 5 2
3 12 149 5 3
4 18 313 5 4
5 NA NA 5 5
6 28 NA 5 6
aq <- head(airquality)
aq[c("Wind","Temp")] <- vector("list",2)
aq
Ozone Solar.R Month Day
1 41 190 5 1
2 36 118 5 2
3 12 149 5 3
4 18 313 5 4
5 NA NA 5 5
6 28 NA 5 6
However, for lists they differ:
aq <- as.list(head(airquality))
aq[c("Wind","Temp")] <- vector("list",2)
aq
$Ozone
[1] 41 36 12 18 NA 28
$Solar.R
[1] 190 118 149 313 NA NA
aq <- as.list(head(airquality))
aq[c("Wind","Temp")] <- NULL
aq
$Ozone
[1] 41 36 12 18 NA 28
$Solar.R
[1] 190 118 149 313 NA NA
On 26 Jun 2017, at 04:40 , Hong Ooi via R-devel <r-devel at r-project.org> wrote:
The behaviour of within() with list input changes if you delete 2 or more variables, compared to deleting one:
l <- list(x=1, y=2, z=3)
within(l,
{
rm(z)
})
#$x
#[1] 1
#
#$y
#[1] 2
within(l, {
rm(y)
rm(z)
})
#$x
#[1] 1
#
#$y
#NULL
#
#$z
#NULL
When 2 or more variables are deleted, the list entries are instead set to NULL. Is this intended?