From pperry at stern.nyu.edu  Fri Dec  1 04:45:21 2017
From: pperry at stern.nyu.edu (Patrick Perry)
Date: Thu, 30 Nov 2017 22:45:21 -0500
Subject: [Rd] Bug is as.matrix.data.frame with nested data.frame
Message-ID: <5A20D051.40102@stern.nyu.edu>

Converting a data.frame with a nested data.frame to a matrix fails:

x <- structure(list(a = data.frame(letters)),
                class = "data.frame",
                row.names = .set_row_names(26))

as.matrix(x)
#> Error in ncol(xj) : object 'xj' not found

The offending code is here, in the definition of as.matrix.data.frame 
(source/base/all.R):

     for (j in pseq) {
         if (inherits(X[[j]], "data.frame") && ncol(xj) > 1L)
             X[[j]] <- as.matrix(X[[j]])
         xj <- X[[j]]

It should be ncol(X[[j]]), not ncol(xj). Also, the code would be more 
generic if it used is.data.frame here instead of inherits(, "data.frame").


Patrick



[Rd] Bug is as.matrix.data.frame with nested data.frame
Patrick Perry