gpt4 book ai didi

r - 将 kable 导出到镜像时的 XDG_RUNTIME_DIR (Rstudio + Ubuntu 20.04)

转载 作者:行者123 更新时间:2023-12-04 19:05:11 26 4
gpt4 key购买 nike

我正在尝试导出在 R 中使用 kableExtra 制作的表。它在 R Studio 环境中看起来不错,但如果我尝试导出它,它会给我这个错误:

> kable(csv) %>%                                                          
+ kable_styling("striped", full_width = F, htmltable_class = 'Liberation Sans') %>%
+ kable_minimal() %>%
+ save_kable(file = paste0(outdir, name, '.png'), bs_theme = "flatly",
+ zoom = 1.5)
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-cesarkero'
error: XDG_RUNTIME_DIR not set in the environment.
TypeError: Attempting to change the setter of an unconfigurable property.
TypeError: Attempting to change the setter of an unconfigurable property.
Error in magick_image_trim(image, fuzz) :
rsession: geometry does not contain image `/home/cesarkero/HDD/D4/GoogleDrive/Proyectos/Master_UNED/01_Materias/06_EE/07_Trabajo/03_Resultados/04_CONSOLIDADOS/07a.png' @ warning/attribute.c/GetImageBoundingBox/247
该文件已导出,但完全为空。
这是用作 csv 对象的文件: https://drive.google.com/file/d/1fmplGNKB7MSKvXpNI_YrThE1F2EKszTf/view?usp=sharing

2022 年 4 月 19 日更新
如果我尝试这个,我会得到一个类似的错误:
> webshot::install_phantomjs()
Error: invalid version specification ‘QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-cesarkero'’
我已经在 linux 终端中安装了 phantomjs:
sudo apt-get install -y phantomjs
这是我的 session 信息():
> sessionInfo()
R version 4.1.3 (2022-03-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.4 LTS

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3

locale:
[1] LC_CTYPE=es_ES.UTF-8 LC_NUMERIC=C
[3] LC_TIME=es_ES.UTF-8 LC_COLLATE=es_ES.UTF-8
[5] LC_MONETARY=es_ES.UTF-8 LC_MESSAGES=es_ES.UTF-8
[7] LC_PAPER=es_ES.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=es_ES.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] landtools_0.1.0 lubridate_1.8.0 plyr_1.8.6
[4] data.table_1.14.2 raster_3.5-15 rgeos_0.5-9
[7] rgdal_1.5-28 sp_1.4-6 exifr_0.3.2
[10] nngeo_0.4.5 spatstat_2.3-3 spatstat.linnet_2.3-2
[13] spatstat.core_2.4-0 rpart_4.1.16 nlme_3.1-157
[16] spatstat.random_2.1-0 spatstat.geom_2.3-2 spatstat.data_2.1-2
[19] purrr_0.3.4 readODS_1.7.0 stringr_1.4.0
[22] mapview_2.10.0 dplyr_1.0.8 readr_2.1.2
[25] sf_1.0-7 magrittr_2.0.3 magick_2.7.3
[28] kableExtra_1.3.4

loaded via a namespace (and not attached):
[1] spatstat.sparse_2.1-0 satellite_1.0.4 webshot_0.5.2
[4] httr_1.4.2 tools_4.1.3 utf8_1.2.2
[7] R6_2.5.1 KernSmooth_2.23-20 DBI_1.1.2
[10] mgcv_1.8-40 colorspace_2.0-3 processx_3.5.2
[13] tidyselect_1.1.2 leaflet_2.1.0 compiler_4.1.3
[16] leafem_0.1.6 cli_3.2.0 rvest_1.0.2
[19] xml2_1.3.3 scales_1.1.1 classInt_0.4-3
[22] callr_3.7.0 proxy_0.4-26 rappdirs_0.3.3
[25] goftest_1.2-3 systemfonts_1.0.4 digest_0.6.29
[28] foreign_0.8-82 spatstat.utils_2.3-0 rmarkdown_2.13
[31] svglite_2.1.0 base64enc_0.1-3 pkgconfig_2.0.3
[34] htmltools_0.5.2 fastmap_1.1.0 htmlwidgets_1.5.4
[37] rlang_1.0.2 rstudioapi_0.13 generics_0.1.2
[40] crosstalk_1.2.0 Matrix_1.4-1 Rcpp_1.0.8.2
[43] munsell_0.5.0 fansi_1.0.3 abind_1.4-5
[46] lifecycle_1.0.1 terra_1.5-21 stringi_1.7.6
[49] maptools_1.1-3 grid_4.1.3 crayon_1.5.1
[52] deldir_1.0-6 lattice_0.20-45 splines_4.1.3
[55] tensor_1.5 hms_1.1.1 ps_1.6.0
[58] knitr_1.37 pillar_1.7.0 codetools_0.2-18
[61] stats4_4.1.3 glue_1.6.2 evaluate_0.15
[64] png_0.1-7 vctrs_0.4.0 tzdb_0.2.0
[67] polyclip_1.10-0 assertthat_0.2.1 xfun_0.30
[70] e1071_1.7-9 class_7.3-20 viridisLite_0.4.0
[73] tibble_3.1.6 units_0.8-0 ellipsis_0.3.2

最佳答案

首先你需要安装phantomjs来自 webshot使用以下代码打包:

webshot::install_phantomjs()
之后,您可以运行以下代码,将您的表格输出为 table.png :
library(knitr)
library(kableExtra)
library(magrittr)

kable(csv) %>%
kable_styling("striped", full_width = F, htmltable_class = 'Liberation Sans') %>%
kable_minimal() %>%
save_kable(file = "table.png", bs_theme = "flatly", zoom = 1.5)
输出如下所示:
enter image description here
请注意,您的 table 真的很大。
这是我的 sessionInfo :
> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS 12.3.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] nl_NL.UTF-8/nl_NL.UTF-8/nl_NL.UTF-8/C/nl_NL.UTF-8/nl_NL.UTF-8

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

other attached packages:
[1] readxl_1.3.1 ggforce_0.3.3 dummies_1.5.6 plyr_1.8.6 magrittr_2.0.3 knitr_1.37
[7] kableExtra_1.3.4 terra_1.5-21 reshape_0.8.8 epitools_0.5-10.1 forcats_0.5.1 stringr_1.4.0
[13] readr_2.1.2 tidyverse_1.3.1 DALEXtra_2.1.1 DALEX_2.4.0 mlbench_2.1-3 yardstick_0.0.9
[19] workflowsets_0.1.0 workflows_0.2.4 tune_0.1.6 tidyr_1.2.0 tibble_3.1.6 rsample_0.1.1
[25] recipes_0.2.0 purrr_0.3.4 parsnip_0.2.0 modeldata_0.1.1 infer_1.0.0 ggplot2_3.3.5
[31] dplyr_1.0.8 dials_0.1.0 scales_1.1.1 broom_0.7.12 tidymodels_0.1.4 mapview_2.10.0

loaded via a namespace (and not attached):
[1] utf8_1.2.2 reticulate_1.24 tidyselect_1.1.2 htmlwidgets_1.5.4 grid_4.1.0 pROC_1.18.0
[7] munsell_0.5.0 codetools_0.2-18 units_0.8-0 future_1.24.0 withr_2.5.0 colorspace_2.0-3
[13] highr_0.9 uuid_1.0-4 rstudioapi_0.13 stats4_4.1.0 Rttf2pt1_1.3.8 listenv_0.8.0
[19] labeling_0.4.2 polyclip_1.10-0 plotROC_2.2.1 bit64_4.0.5 DiceDesign_1.9 farver_2.1.0
[25] rprojroot_2.0.2 parallelly_1.30.0 vctrs_0.4.0 generics_0.1.2 ipred_0.9-12 xfun_0.30
[31] R6_2.5.1 doParallel_1.0.17 ggiraph_0.8.2 flexmix_2.3-17 lhs_1.1.4 assertthat_0.2.1
[37] vroom_1.5.7 nnet_7.3-17 gtable_0.3.0 globals_0.14.0 processx_3.5.2 timeDate_3043.102
[43] rlang_1.0.2 systemfonts_1.0.4 modMax_1.1 splines_4.1.0 rgdal_1.5-28 extrafontdb_1.0
[49] lazyeval_0.2.2 ModelMetrics_1.2.2.2 yaml_2.3.5 reshape2_1.4.4 modelr_0.1.8 crosstalk_1.2.0
[55] backports_1.4.1 caret_6.0-90 extrafont_0.17 tools_4.1.0 lava_1.6.10 ellipsis_0.3.2
[61] raster_3.5-15 jquerylib_0.1.4 proxy_0.4-26 Rcpp_1.0.8.3 base64enc_0.1-3 progress_1.2.2
[67] classInt_0.4-3 ps_1.6.0 prettyunits_1.1.1 rpart_4.1.16 haven_2.4.3 fs_1.5.2
[73] here_1.0.1 leafem_0.1.6 furrr_0.2.3 magick_2.7.3 data.table_1.14.2 SparseM_1.81
[79] reprex_2.0.1 GPfit_1.0-8 hms_1.1.1 evaluate_0.15 leaflet_2.0.3.9000 compiler_4.1.0
[85] ingredients_2.2.0 KernSmooth_2.23-20 crayon_1.5.1 htmltools_0.5.2 tzdb_0.2.0 lubridate_1.8.0
[91] DBI_1.1.2 tweenr_1.0.2 dbplyr_2.1.1 MASS_7.3-55 sf_1.0-7 Matrix_1.4-0
[97] cli_3.2.0 parallel_4.1.0 gower_1.0.0 igraph_1.2.11 pkgconfig_2.0.3 sp_1.4-6
[103] plotly_4.10.0 xml2_1.3.3 foreach_1.5.2 svglite_2.1.0 bslib_0.3.1 hardhat_0.2.0
[109] webshot_0.5.2 prodlim_2019.11.13 rvest_1.0.2 callr_3.7.0 digest_0.6.29 rmarkdown_2.13
[115] cellranger_1.1.0 kernlab_0.9-29 gtools_3.9.2 satellite_1.0.4 modeltools_0.2-23 lifecycle_1.0.1
[121] nlme_3.1-155 jsonlite_1.8.0 viridisLite_0.4.0 fansi_1.0.3 pillar_1.7.0 lattice_0.20-45
[127] fastmap_1.1.0 httr_1.4.2 survival_3.3-1 glue_1.6.2 png_0.1-7 iterators_1.0.14
[133] bit_4.0.4 class_7.3-20 stringi_1.7.6 sass_0.4.1 e1071_1.7-9 future.apply_1.8.1

关于r - 将 kable 导出到镜像时的 XDG_RUNTIME_DIR (Rstudio + Ubuntu 20.04),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71855278/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com