Bug 17225 - Adding named element to nested element of recursive object does not add the name for pairlists, calls, and expressions.
Summary: Adding named element to nested element of recursive object does not add the n...
Status: ASSIGNED
Alias: None
Product: R
Classification: Unclassified
Component: Language (show other bugs)
Version: R-devel (trunk)
Hardware: Other Other
: P5 normal
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2017-02-18 19:28 UTC by Bill Dunlap
Modified: 2017-02-22 13:53 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bill Dunlap 2017-02-18 19:28:08 UTC
If I add an element to an interior element of a recursive object by
using a character vector with length more than 1 in [[<-, then the name
at end of the vector is added for lists but not for other recursive
types like pairlists, expressions, and calls.

{
   aList <- list(A=list(A1=11,A2=12),B=2)
   aList[[c("A","A3")]] <- list(C1=13)
   str(aList)
}
#List of 2
# $ A:List of 3
#  ..$ A1: num 11
#  ..$ A2: num 12
#  ..$ A3:List of 1
#  .. ..$ C1: num 13
# $ B: num 2
{
   aPairlist <- pairlist(A=pairlist(A1=11,A2=12),B=2)
   aPairlist[[c("A","A3")]] <- pairlist(A31=131)
   str(aPairlist)
}
#Dotted pair list of 2
# $ A:Dotted pair list of 3
#  ..$ A1: num 11
#  ..$ A2: num 12
#  ..$   :Dotted pair list of 1
#  .. ..$ A31: num 131
# $ B: num 2
{
   aCall <- quote(foo(A=bar(A1=11,A2=12),B=2))
   aCall[[c("A","A3")]] <- quote(baz(A31=131))
   str(aCall)
}
# language foo(A = bar(A1 = 11, A2 = 12, baz(A31 = 131)), B = 2)
{
   anExpression <- expression(A=foo(A1=11,A2=12),B=2)
   anExpression[[c("A","A3")]] <- quote(baz(A31=131))
   str(anExpression)
}
# structure(expression(A = foo(A1 = 11, A2 = 12, baz(A31 = 131)), B = 2), .Names = c("A", "B"))

If I replace x[[v]] with x[[v[1]]][[v[2]]]...[[v[length(v)]]]
the the new name, v[length(v)], is added. E.g.,
   aPairlist <- pairlist(A=pairlist(A1=11,A2=12),B=2)
   aPairlist[["A"]][["A3"]] <- pairlist(A31=131)
   str(aPairlist)
   #Dotted pair list of 2
   # $ A:Dotted pair list of 3
   #  ..$ A1: num 11
   #  ..$ A2: num 12
   #  ..$ A3:Dotted pair list of 1
   #  .. ..$ A31: num 131
   # $ B: num 2

> sessionInfo()
R Under development (unstable) (2017-02-15 r72177)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_3.4.0