Open lucygarner opened 2 years ago
This error also occurs if I extract the embeddings and metavars_df and run HarmonyMatrix
.
I have traced the error to the following part of HarmonyMatrix
.
phi <- Reduce(rbind, lapply(vars_use, function(var_use) {
t(onehot(meta_data[[var_use]]))
}))
Within this, it is the onehot
function that is causing the error.
harmony:::onehot
function (x)
{
data.frame(x) %>% tibble::rowid_to_column("row_id") %>% dplyr::mutate(dummy = 1) %>%
tidyr::spread(x, .data$dummy, fill = 0) %>% dplyr::select(-.data$row_id) %>%
as.matrix
}
Changing dplyr::select(-.data$row_id)
to dplyr::select(-row_id)
fixes the issue.
Why it is working on my MacBook and not on CentOS 7 I can't explain since they are using the same version of dplyr.
I am also confused by the factor that the onehot
function I find in harmony/utils.R
looks completely different:
onehot <- function(x) {
res <- model.matrix(~0 + x)
colnames(res) <- gsub('^x(.*)', '\\1', colnames(res))
return(res)
}
I got the same error today. Using the following code before running RunHarmony
solved my problem:
harmony.onehot.new <- function (x)
{
data.frame(x) %>% tibble::rowid_to_column("row_id") %>% dplyr::mutate(dummy = 1) %>%
tidyr::spread(x, .data$dummy, fill = 0) %>% dplyr::select(-row_id) %>%
as.matrix
}
environment(harmony.onehot.new) <- asNamespace('harmony')
assignInNamespace("onehot", harmony.onehot.new, ns = "harmony")
Thanks, I fixed it in a similar way.
Reprex:
library(tidyverse)
onehot <- function (x) {
data.frame(x) %>%
tibble::rowid_to_column("row_id") %>%
dplyr::mutate(dummy = 1) %>%
tidyr::spread(x, .data$dummy, fill = 0) %>%
dplyr::select(-.data$row_id) %>%
as.matrix
}
donor <- factor(c("1", "2", "1", "3", "4", "2", "4", "1"))
onehot(donor)
#> Error in dplyr::select(., -.data$row_id): <text>:1:5: unexpected symbol
#> 1: Use of
#> ^
sessionInfo()
#> R version 4.2.0 (2022-04-22)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: CentOS Linux 7 (Core)
#>
#> Matrix products: default
#> BLAS: /Filers/package/R-base/4.2.0/lib64/R/lib/libRblas.so
#> LAPACK: /Filers/package/R-base/4.2.0/lib64/R/lib/libRlapack.so
#>
#> locale:
#> [1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C
#> [3] LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8
#> [5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8
#> [7] LC_PAPER=en_GB.UTF-8 LC_NAME=C
#> [9] LC_ADDRESS=C LC_TELEPHONE=C
#> [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] forcats_0.5.2 stringr_1.4.1 dplyr_1.0.10 purrr_0.3.5
#> [5] readr_2.1.3 tidyr_1.2.1 tibble_3.1.8 ggplot2_3.3.6
#> [9] tidyverse_1.3.2
#>
#> loaded via a namespace (and not attached):
#> [1] lubridate_1.8.0 assertthat_0.2.1 digest_0.6.29
#> [4] utf8_1.2.2 R6_2.5.1 cellranger_1.1.0
#> [7] backports_1.4.1 reprex_2.0.2 evaluate_0.17
#> [10] httr_1.4.4 highr_0.9 pillar_1.8.1
#> [13] rlang_1.0.5 googlesheets4_1.0.1 readxl_1.4.1
#> [16] rstudioapi_0.14 R.utils_2.12.0 R.oo_1.25.0
#> [19] rmarkdown_2.17 styler_1.7.0 googledrive_2.0.0
#> [22] munsell_0.5.0 broom_1.0.1 compiler_4.2.0
#> [25] modelr_0.1.9 xfun_0.30 pkgconfig_2.0.3
#> [28] htmltools_0.5.3 tidyselect_1.2.0 fansi_1.0.3
#> [31] crayon_1.5.2 tzdb_0.3.0 dbplyr_2.2.1
#> [34] withr_2.5.0 R.methodsS3_1.8.2 grid_4.2.0
#> [37] jsonlite_1.8.2 gtable_0.3.1 lifecycle_1.0.1
#> [40] DBI_1.1.3 magrittr_2.0.3 scales_1.2.1
#> [43] cli_3.4.1 stringi_1.7.8 fs_1.5.2
#> [46] xml2_1.3.3 ellipsis_0.3.2 generics_0.1.3
#> [49] vctrs_0.4.2 tools_4.2.0 R.cache_0.16.0
#> [52] glue_1.6.2 hms_1.1.2 fastmap_1.1.0
#> [55] yaml_2.3.5 colorspace_2.0-3 gargle_1.2.1
#> [58] rvest_1.0.3 knitr_1.40 haven_2.5.1
Hi,
I am getting the following error when I run
RunHarmony
on my Seurat object and I can't work out where thisdplyr::select()
is coming from.seurat_object <- RunHarmony(seurat_object, group.by.vars = "donor")
rlang::last_error()
Best wishes, Lucy
sessionInfo()