In the last weeks, I had problems with rbind.hyperframe since it crashes with the following error:
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : row names supplied are of the wrong length
stop("row names supplied are of the wrong length")
(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)) ...
do.call(data.frame, append(aarg[dfcolumns], list(row.names = row.names, check.rows = check.rows, check.names = check.names, stringsAsFactors = stringsAsFactors)))
(function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, stringsAsFactors = default.stringsAsFactors()) { aarg <- list(...) ...
do.call(hyperframe, append(rslt, list(stringsAsFactors = FALSE, row.names = rona)))
rbind.hyperframe(hfs, hf)
I found out that rbind.hyperframe was changed in one of the last updates since v1.60. A section for creating row names was added. If I remove that section, everything works fine again.
# 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)
}
Example code, where rbind.hyperframe causes the error
EDIT: Removed first example since it was not reproducible. Here are two short examples.
> 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
I tested them on a different computer with an older version of spatstat as well. The new version of cbind.hyperframe changes the row names as well.
------ Another computer without problem -------------
> 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
I confirm that this is a bug. It is now fixed in the development version of spatstat
(version 1.64-0.001 and later).
Bug reports should be posted at the spatstat package bug reports page