更新到 v1.63 后 spatstat rbind.hyperframe 崩溃

spatstat rbind.hyperframe crashes after update to v1.63

在过去的几周里,我遇到了 rbind.hyperframe 的问题,因为它崩溃并出现以下错误:

Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : row names supplied are of the wrong length

  1. stop("row names supplied are of the wrong length")

  2. (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, fix.empty.names = TRUE, stringsAsFactors = default.stringsAsFactors()) { data.row.names <- if (check.rows && is.null(row.names)) ...

  3. do.call(data.frame, append(aarg[dfcolumns], list(row.names = row.names, check.rows = check.rows, check.names = check.names, stringsAsFactors = stringsAsFactors)))

  4. (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, stringsAsFactors = default.stringsAsFactors()) { aarg <- list(...) ...

  5. do.call(hyperframe, append(rslt, list(stringsAsFactors = FALSE, row.names = rona)))

  6. rbind.hyperframe(hfs, hf)

我发现 rbind.hyperframe 在自 v1.60 以来的最后一次更新中发生了变化。添加了用于创建行名称的部分。如果我删除该部分,一切都会恢复正常。

# rbind.hyperframe of spatstat v1.63-3
function (...) 
{
    argh <- list(...)
    if (length(argh) == 0) 
        return(NULL)
    argh <- lapply(argh, as.hyperframe)
    nargh <- length(argh)
    if (nargh == 1) 
        return(argh[[1L]])
    dfs <- lapply(argh, as.data.frame, discard = FALSE)
    dfall <- do.call(rbind, dfs)
    dfs0 <- lapply(argh, as.data.frame, discard = TRUE, warn = FALSE)
    df0all <- do.call(rbind, dfs0)
    rslt <- list()
    nam <- names(dfall)
    nam0 <- names(df0all)
    for (k in seq_along(nam)) {
        nama <- nam[k]
        if (nama %in% nam0) {
            rslt[[k]] <- dfall[, k]
        }
        else {
            hdata <- lapply(argh, "[", j = nama, drop = FALSE)
            hdata <- lapply(lapply(hdata, as.list), getElement, 
                name = nama)
            hh <- hdata[[1L]]
            for (j in 2:nargh) {
                hh <- append(hh, hdata[[j]])
            }
            rslt[[k]] <- hh
        }
    }
    rona <- sapply(dfs, row.names) # New code
    rona <- make.names(rona, unique = TRUE) # New code
    names(rslt) <- nam
    out <- do.call(hyperframe, append(rslt, list(stringsAsFactors = FALSE, 
        row.names = rona))) # new code
    return(out)
}
# rbind.hyperframe of spatstat v1.60-1
function (...) 
{
    argh <- list(...)
    if (length(argh) == 0) 
        return(NULL)
    argh <- lapply(argh, as.hyperframe)
    nargh <- length(argh)
    if (nargh == 1) 
        return(argh[[1L]])
    dfs <- lapply(argh, as.data.frame, discard = FALSE)
    dfall <- do.call(rbind, dfs)
    dfs0 <- lapply(argh, as.data.frame, discard = TRUE, warn = FALSE)
    df0all <- do.call(rbind, dfs0)
    rslt <- list()
    nam <- names(dfall)
    nam0 <- names(df0all)
    for (k in seq_along(nam)) {
        nama <- nam[k]
        if (nama %in% nam0) {
            rslt[[k]] <- dfall[, k]
        }
        else {
            hdata <- lapply(argh, "[", j = nama, drop = FALSE)
            hdata <- lapply(lapply(hdata, as.list), getElement, 
                name = nama)
            hh <- hdata[[1L]]
            for (j in 2:nargh) {
                hh <- append(hh, hdata[[j]])
            }
            rslt[[k]] <- hh
        }
    }
    names(rslt) <- nam
    out <- do.call(hyperframe, append(rslt, list(stringsAsFactors = FALSE)))
    return(out)
}

示例代码,其中 rbind.hyperframe 导致错误


编辑:删除了第一个示例,因为它不可重现。 这里有两个简短的例子。

> library(spatstat)
Lade nötiges Paket: spatstat.data
Lade nötiges Paket: nlme
Lade nötiges Paket: rpart

spatstat 1.63-3       (nickname: ‘Wet paint’) 
For an introduction to spatstat, type ‘beginner’ 

> 
> for (i in 1:3) {
+     df <- data.frame(1,2,3,4,5)
+     list_of <- listof(rnorm(10))
+     
+     hf <- cbind.hyperframe(df, list_of)
+     
+     if (i == 1) {
+         hfs <- hf
+     } else {
+         hfs <- rbind.hyperframe(hfs, hf)
+     }
+ }
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE,  : 
  row names supplied are of the wrong length
> 
> print(hf)
Hyperframe:
   X1 X2 X3 X4 X5        V1
X1  1  2  3  4  5 (numeric)
> print(hfs)
Hyperframe:
     X1 X2 X3 X4 X5        V1
X1    1  2  3  4  5 (numeric)
X1.1  1  2  3  4  5 (numeric)
> 
> 
> for (i in 1:3) {
+     df <- data.frame(1,2,3,4,5)
+     hf <- as.hyperframe.data.frame(df)
+ 
+     if (i == 1) {
+         hfs <- hf
+     } else {
+         hfs <- rbind.hyperframe(hfs, hf)
+     }
+ }
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE,  : 
  row names supplied are of the wrong length
> 
> print(hf)
Hyperframe:
  X1 X2 X3 X4 X5
1  1  2  3  4  5
> print(hfs)
Hyperframe:
     X1 X2 X3 X4 X5
X1    1  2  3  4  5
X1.1  1  2  3  4  5
> 
> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)

Matrix products: default

Random number generation:
 RNG:     Mersenne-Twister 
 Normal:  Inversion 
 Sample:  Rounding 

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C                    LC_TIME=German_Germany.1252    

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

other attached packages:
[1] spatstat_1.63-3     rpart_4.1-15        nlme_3.1-144        spatstat.data_1.4-3

loaded via a namespace (and not attached):
 [1] compiler_3.6.3        deldir_0.1-25         Matrix_1.2-18         spatstat.utils_1.17-0 tools_3.6.3          
 [6] mgcv_1.8-31           abind_1.4-5           splines_3.6.3         grid_3.6.3            polyclip_1.10-0      
[11] goftest_1.2-2         lattice_0.20-38       tensor_1.5 

我也在另一台使用旧版本 spatstat 的计算机上测试了它们。 cbind.hyperframe 的新版本也更改了行名称。

------另一台没有问题的电脑------------

> library(spatstat)
Lade nötiges Paket: spatstat.data
Lade nötiges Paket: nlme
Lade nötiges Paket: rpart

spatstat 1.60-1       (nickname: ‘Swinging Sixties’) 
For an introduction to spatstat, type ‘beginner’ 


Note: R version 3.6.1 (2019-07-05) is more than 9 months old; we strongly recommend upgrading to the latest version
> 
> for (i in 1:3) {
+     df <- data.frame(1,2,3,4,5)
+     list_of <- listof(rnorm(10))
+     
+     hf <- cbind.hyperframe(df, list_of)
+     
+     if (i == 1) {
+         hfs <- hf
+     } else {
+         hfs <- rbind.hyperframe(hfs, hf)
+     }
+ }
> print(hf)
Hyperframe:
  X1 X2 X3 X4 X5        V1
1  1  2  3  4  5 (numeric)
> print(hfs)
Hyperframe:
  X1 X2 X3 X4 X5        V1
1  1  2  3  4  5 (numeric)
2  1  2  3  4  5 (numeric)
3  1  2  3  4  5 (numeric)
> 
> 
> for (i in 1:3) {
+     df <- data.frame(1,2,3,4,5)
+     hf <- as.hyperframe.data.frame(df)
+ 
+     if (i == 1) {
+         hfs <- hf
+     } else {
+         hfs <- rbind.hyperframe(hfs, hf)
+     }
+ }
> print(hf)
Hyperframe:
  X1 X2 X3 X4 X5
1  1  2  3  4  5
> print(hfs)
Hyperframe:
  X1 X2 X3 X4 X5
1  1  2  3  4  5
2  1  2  3  4  5
3  1  2  3  4  5
> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

Random number generation:
 RNG:     Mersenne-Twister 
 Normal:  Inversion 
 Sample:  Rounding 

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252   
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C                   
[5] LC_TIME=German_Germany.1252    

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

other attached packages:
[1] spatstat_1.60-1     rpart_4.1-15        nlme_3.1-140        spatstat.data_1.4-0

loaded via a namespace (and not attached):
 [1] compiler_3.6.1        deldir_0.1-23         Matrix_1.2-17        
 [4] spatstat.utils_1.13-0 tools_3.6.1           mgcv_1.8-28          
 [7] abind_1.4-5           splines_3.6.1         grid_3.6.1           
[10] polyclip_1.10-0       goftest_1.1-1         lattice_0.20-38      
[13] tensor_1.5 

我确认这是一个错误。它现在已在 spatstat 的开发版本(版本 1.64-0.001 及更高版本)中得到修复。

错误报告应发布在 spatstat package bug reports page