【问题标题】:spatstat rbind.hyperframe crashes after update to v1.63更新到 v1.63 后 spatstat rbind.hyperframe 崩溃
【发布时间】:2020-08-12 18:21:17
【问题描述】:

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

错误(函数(...,row.names = NULL,check.rows = FALSE, check.names = TRUE, : 提供的行名长度错误

  1. stop("提供的行名长度错误")

  2. (函数 (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, fix.empty.names = TRUE, stringsAsFactors = default.stringsAsFactors()) { data.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. (函数 (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, stringsAsFactors = default.stringsAsFactors()) { aarg

  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 

【问题讨论】:

  • 此代码包含未定义的变量(例如path_main_folder),因此该示例不可重现
  • 请提供此示例中使用的.rds 文件,或提供另一个独立的示例来演示该错误。
  • 另外请确认是否加载了spatstat包,使用了Rspatstat的哪个版本。

标签: r rbind spatstat


【解决方案1】:

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

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

【讨论】:

  • 我在 GitHub 上创建了一个问题
  • 此错误修复将很快在 CRAN 上发布为 spatstat 1.64-1
猜你喜欢
  • 2019-07-12
  • 2021-11-16
  • 1970-01-01
  • 2016-08-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-01
  • 2019-07-25
相关资源
最近更新 更多