[Rd] Segmentation fault in subscripting array of lists (PR#904)
David M Smith
dsmith@insightful.com
Tue, 10 Apr 2001 11:50:17 -0700
R clearly shouldn't crash, but tmp[[1, ]] is semantically incorrect. The
result of "[[" is required to be a single value from a vector (or generally,
an array) of the mode of the vector. To select more than one element from
an array, you must use "[". The results from S-PLUS 6 are:
> tmp[[1, ]]
Problem in [[: Attempt to select more than one element: structure(list(NULL,
NULL, NULL, list(fred = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)), NULL, NUL....
Use traceback() to see the call stack
This error message indicates the error. Using "[" gives the correct result:
> tmp[1, ]
[[1]]:
NULL
[[2]]:
[[2]]$fred:
[1] 1 2 3 4 5 6 7 8 9 10
[[3]]:
NULL
[[4]]:
NULL
# David Smith
--
David M Smith <dsmith@insightful.com>
S-PLUS Product Marketing Manager, Insightful Corp, Seattle WA
Tel: +1 (206) 283 8802 x360
Fax: +1 (206) 283 0347
MathSoft is now Insightful! See www.insightful.com for details.
> -----Original Message-----
> From: owner-r-devel@stat.math.ethz.ch
> [mailto:owner-r-devel@stat.math.ethz.ch]On Behalf Of
> J.C.Rougier@durham.ac.uk
> Sent: Tuesday, April 10, 2001 07:02
> To: r-devel@stat.math.ethz.ch
> Cc: R-bugs@biostat.ku.dk
> Subject: [Rd] Segmentation fault in subscripting array of lists (PR#904)
>
>
> I get a segmentation fault as follows:
>
> > tmp <- array(list(), c(3, 4))
> > tmp[[1, 2]]
> NULL # as expected
> > tmp[[1, 2]]$fred <- 1:10
> > tmp # as expected
> [,1] [,2] [,3] [,4]
> [1,] "NULL" "List,1" "NULL" "NULL"
> [2,] "NULL" "NULL" "NULL" "NULL"
> [3,] "NULL" "NULL" "NULL" "NULL"
> > tmp[[1, 2]] # as expected
> $fred
> [1] 1 2 3 4 5 6 7 8 9 10
>
> > tmp[[1, ]] # whoops!
> Segmentation fault
>
> Cheers, Jonathan.
>
> --please do not edit the information below--
>
> Version:
> platform = sparc-sun-solaris2.7
> arch = sparc
> os = solaris2.7
> system = sparc, solaris2.7
> status =
> major = 1
> minor = 2.1
> year = 2001
> month = 01
> day = 15
> language = R
>
> Search Path:
> .GlobalEnv, Autoloads, package:base
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
> -.-.-.-.-.-.-
> r-devel mailing list -- Read
> http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
> _._._._._._._
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._