I'm trying to use the waterfall R package to create a waterfall chart, like this, per the example at this link:
category <- c("Sales", "Services", "Fixed Costs",
"Variable Costs", "Taxes")
amount <- c(101000, 52000, -23000, -15000, -10000)
income <- data.frame(category, amount)
library(ggplot2)
library(waterfalls)
waterfall(income)
But getting this error:
Error in unit(rep(just$hjust, n), "npc") : 'x' and 'units' must have length > 0
How can I make it work?
This is the output from my sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.5
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] waterfalls_0.1.2 DBI_1.0.0 ggpubr_0.2 patchwork_0.0.1 forcats_0.4.0 stringr_1.4.0 dplyr_0.8.0.1 purrr_0.3.2
[10] readr_1.3.1 tidyr_0.8.3 tibble_2.1.1 ggplot2_3.1.1 tidyverse_1.2.1 scales_1.0.0 lubridate_1.7.4 magrittr_1.5 RPresto_1.3.2
[19] knitr_1.22 extrafont_0.17 bigrquery_1.1.1
loaded via a namespace (and not attached):
[1] nlme_3.1-139 sf_0.7-4 bit64_0.9-7 httr_1.4.0 tools_3.6.0 backports_1.1.4 rgdal_1.4-3 R6_2.4.0
[9] KernSmooth_2.23-15 rgeos_0.4-3 lazyeval_0.2.2 colorspace_1.4-1 raster_2.8-19 withr_2.1.2 sp_1.3-1 tidyselect_0.2.5
[17] bit_1.1-14 curl_3.3 compiler_3.6.0 extrafontdb_1.0 cli_1.1.0 rvest_0.3.3 formatR_1.6 xml2_1.2.0
[25] labeling_0.3 dygraphs_1.1.1.6 classInt_0.3-3 digest_0.6.18 foreign_0.8-71 rmarkdown_1.12 base64enc_0.1-3 pkgconfig_2.0.2
[33] htmltools_0.3.6 jsonvalidate_1.0.0 htmlwidgets_1.3 rlang_0.3.4 readxl_1.3.1 rstudioapi_0.10 httpcode_0.2.0 shiny_1.3.2
[41] generics_0.0.2 zoo_1.8-5 jsonlite_1.6 futile.logger_1.4.3 Rcpp_1.0.1 munsell_0.5.0 yaml_2.2.0 stringi_1.4.3
[49] jqr_1.1.0 plyr_1.8.4 grid_3.6.0 settings_0.2.4 maptools_0.9-5 parallel_3.6.0 listenv_0.7.0 promises_1.0.1
[57] crayon_1.3.4 geojsonio_0.7.0 miniUI_0.1.1.1 lattice_0.20-38 haven_2.1.0 geojson_0.3.2 hms_0.4.2 pillar_1.3.1
[65] geojsonlint_0.3.0 codetools_0.2-16 futile.options_1.0.1 crul_0.7.4 glue_1.3.1 infuser_0.2.8 evaluate_0.13 V8_2.2
[73] lambda.r_1.2.3 modelr_0.1.4 png_0.1-7 httpuv_1.5.1 Rttf2pt1_1.3.7 cellranger_1.1.0 gtable_0.3.0 future_1.12.0
[81] RDruid_0.2.3 assertthat_0.2.1 xfun_0.6 mime_0.6 xtable_1.8-4 broom_0.5.2 e1071_1.7-1 later_0.8.0
[89] class_7.3-15 units_0.6-2 globals_0.12.4
I just found that not loading my company's internal package actually fixes this issue. There must be a function in my company's package that's breaking this package.
Related
When I preview my R Notebook, the HTML output contains strange characters.
This chunk code and output
gets rendered in HTML as
How should I fix this?
SessionInfo:
R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)
Matrix products: default
locale:
1 LC_COLLATE=Dutch_Netherlands.1252 LC_CTYPE=Dutch_Netherlands.1252 LC_MONETARY=Dutch_Netherlands.1252 LC_NUMERIC=C
[5] LC_TIME=Dutch_Netherlands.1252
other attached packages:
1 plotly_4.9.0 DT_0.6 shinydashboard_0.7.1 shiny_1.3.2 lubridate_1.7.4 forcats_0.4.0
[7] stringr_1.4.0 dplyr_0.8.1 purrr_0.3.2 readr_1.3.1 tidyr_0.8.3 tibble_2.1.1
[13] ggplot2_3.1.1 tidyverse_1.2.1
loaded via a namespace (and not attached):
1 tidyselect_0.2.5 xfun_0.7 haven_2.1.0 lattice_0.20-38 colorspace_1.4-1 generics_0.0.2 viridisLite_0.3.0 htmltools_0.3.6
[9] base64enc_0.1-3 yaml_2.2.0 rlang_0.3.4 pillar_1.4.0 later_0.8.0 glue_1.3.1 withr_2.1.2 modelr_0.1.4
[17] readxl_1.3.1 plyr_1.8.4 munsell_0.5.0 gtable_0.3.0 cellranger_1.1.0 rvest_0.3.4 htmlwidgets_1.3 evaluate_0.14
[25] knitr_1.23 httpuv_1.5.1 crosstalk_1.0.0 broom_0.5.2 Rcpp_1.0.1 xtable_1.8-4 scales_1.0.0 backports_1.1.4
[33] promises_1.0.1 jsonlite_1.6 mime_0.6 hms_0.4.2 digest_0.6.19 stringi_1.4.3 grid_3.6.0 cli_1.1.0
[41] tools_3.6.0 magrittr_1.5 lazyeval_0.2.2 crayon_1.3.4 pkgconfig_2.0.2 data.table_1.12.2 xml2_1.2.0 rmarkdown_1.13
[49] assertthat_0.2.1 httr_1.4.0 rstudioapi_0.10 R6_2.4.0 nlme_3.1-139 compiler_3.6.0
I want to read a bunch of files in from a directory using a loop, with a set naming convention (e.g., File_a_1.Rds, File_a_2.Rds, File_b_1.Rds, etc.). There might be gaps in the file names (e.g., File_a_2.Rds might be missing), but gaps themselves aren't a problem. To account for gaps, I've tried using file.exists(): if (file.exists(fname)) readRDS(fname) else NULL, but I then get an error message indicating that R tried to do readRDS(fname) even though fname doesn't exist: Error in readRDS(fname) : error reading from connection. What's going on here?
Other means of testing this if-statement indicate that it works when I'm not trying to use readRDS(). For example, if (file.exists(fname)) "apple" else "banana" gives me apples and bananas where I expect them, so it's weird that the same logic isn't applied to if (file.exists(fname)) readRDS(fname) else NULL. Likewise, using ifTRUE() doesn't help things, contra an earlier post.
N.B. The type of loop shouldn't matter, but in this case I'm using mclapply() to vectorize the operation. And normally I'd just do something like dir() %>% do.call(readRDS), but then the files would be in the wrong order and without the nested structure I'm looking for.
Session info:
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.6 LTS
Matrix products: default
BLAS: /usr/lib/atlas-base/atlas/libblas.so.3.0
LAPACK: /usr/lib/atlas-base/atlas/liblapack.so.3.0
locale:
[1] LC_CTYPE=en_NZ.UTF-8 LC_NUMERIC=C LC_TIME=en_NZ.UTF-8 LC_COLLATE=en_NZ.UTF-8
[5] LC_MONETARY=en_NZ.UTF-8 LC_MESSAGES=en_NZ.UTF-8 LC_PAPER=en_NZ.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_NZ.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] grid parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] DMwR_0.4.1 ROCR_1.0-7 gplots_3.0.1.1 caret_6.0-81 lattice_0.20-38 ranger_0.11.1
[7] lmerTest_3.1-0 lme4_1.1-20 Matrix_1.2-15 magrittr_1.5 forcats_0.4.0 stringr_1.4.0
[13] dplyr_0.8.0.1 purrr_0.3.0 readr_1.3.1 tidyr_0.8.2 tibble_2.0.1 ggplot2_3.1.0
[19] tidyverse_1.2.1
loaded via a namespace (and not attached):
[1] nlme_3.1-137 bitops_1.0-6 xts_0.11-2 lubridate_1.7.4 httr_1.4.0
[6] numDeriv_2016.8-1 tools_3.5.2 backports_1.1.3 R6_2.4.0 rpart_4.1-13
[11] KernSmooth_2.23-15 lazyeval_0.2.1 colorspace_1.4-0 nnet_7.3-12 withr_2.1.2
[16] tidyselect_0.2.5 curl_3.3 compiler_3.5.2 cli_1.0.1 rvest_0.3.2
[21] xml2_1.2.0 caTools_1.17.1.1 scales_1.0.0 digest_0.6.18 minqa_1.2.4
[26] rmarkdown_1.11 base64enc_0.1-3 pkgconfig_2.0.2 htmltools_0.3.6 TTR_0.23-4
[31] rlang_0.3.1 readxl_1.3.0 rstudioapi_0.9.0 quantmod_0.4-13 generics_0.0.2
[36] zoo_1.8-4 jsonlite_1.6 gtools_3.8.1 ModelMetrics_1.2.2 Rcpp_1.0.0
[41] munsell_0.5.0 abind_1.4-5 stringi_1.3.1 yaml_2.2.0 MASS_7.3-51.1
[46] plyr_1.8.4 recipes_0.1.4 gdata_2.18.0 crayon_1.3.4 haven_2.1.0
[51] splines_3.5.2 hms_0.4.2 knitr_1.21 pillar_1.3.1 reshape2_1.4.3
[56] codetools_0.2-16 stats4_3.5.2 glue_1.3.0 evaluate_0.13 data.table_1.12.0
[61] modelr_0.1.4 nloptr_1.2.1 foreach_1.4.4 cellranger_1.1.0 gtable_0.2.0
[66] assertthat_0.2.0 xfun_0.5 gower_0.1.2 prodlim_2018.04.18 broom_0.5.1
[71] class_7.3-15 survival_2.43-3 timeDate_3043.102 iterators_1.0.10 lava_1.6.5
[76] ipred_0.9-8 ```
When I try to render an rmarkdown file with a ggplot image, all the chunks work that do not contain a ggplot image and it fails without an error when it tries to run said chunk.
The output I get in my terminal is
Killed
It runs fine on my local machine with the latest version of R and all the packages updated.
Below is the environment I am using in docker to try to run the same thing (when it fails).
R version 3.4.1 (2017-06-30)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Amazon Linux AMI 2017.09
Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so
locale:
[1] C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] bindrcpp_0.2.2 blogdown_0.10 rmarkdown_1.11 here_0.1
[5] PRROC_1.3.1 DT_0.5 forcats_0.3.0
stringr_1.3.1
[9] dplyr_0.7.8 purrr_0.2.5 readr_1.3.1
tidyr_0.8.2
[13] tibble_2.0.1 ggplot2_3.1.0 tidyverse_1.2.1
data.table_1.12.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.0 lubridate_1.7.4 lattice_0.20-35
assertthat_0.2.0
[5] rprojroot_1.3-2 digest_0.6.18 mime_0.6 R6_2.3.0
[9] cellranger_1.1.0 plyr_1.8.4 backports_1.1.3 evaluate_0.12
[13] httr_1.4.0 pillar_1.3.1 rlang_0.3.1
lazyeval_0.2.1
[17] readxl_1.2.0 rstudioapi_0.9.0 Matrix_1.2-10
reticulate_1.10
[21] htmlwidgets_1.3 munsell_0.5.0 shiny_1.2.0 broom_0.5.1
[25] compiler_3.4.1 httpuv_1.4.5.1 modelr_0.1.2 xfun_0.4
[29] pkgconfig_2.0.2 htmltools_0.3.6 tidyselect_0.2.5 crayon_1.3.4
[33] withr_2.1.2 later_0.7.5 grid_3.4.1 nlme_3.1-131
[37] jsonlite_1.6 xtable_1.8-3 gtable_0.2.0 magrittr_1.5
[41] scales_1.0.0 cli_1.0.1 stringi_1.2.4
promises_1.0.1
[45] xml2_1.2.0 generics_0.0.2 tools_3.4.1 glue_1.3.0
[49] hms_0.4.2 crosstalk_1.0.0 yaml_2.2.0
colorspace_1.4-0
[53] rvest_0.3.2 knitr_1.21 bindr_0.1.1 haven_2.0.0
I want to print a plus minus sign of the form ± into a string in R, so that I can place that string a table with kableextra
Here is the structure of the string :
x = paste0("first_string", 2, "±", 3, "second_string", collapse = "")
However I get the following output:
"first_string2\302\2613second_string"
what should I do to have the output:
"first_string2±3second_string"
I found that \302\261 is the encoding for ± in Octal Escape Sequence according to this website or this website
EDIT Here is the output of sessionInfo():
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS 10.14
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
locale:
[1] C
attached base packages:
[1] splines stats graphics grDevices utils datasets methods base
other attached packages:
[1] bindrcpp_0.2.2 rms_5.1-2 SparseM_1.77 Hmisc_4.1-1 Formula_1.2-3
[6] lattice_0.20-35 blme_1.0-4 emmeans_1.2.4 lme4_1.1-18-1 Matrix_1.2-14
[11] multcomp_1.4-8 TH.data_1.0-8 MASS_7.3-49 mvtnorm_1.0-8 survminer_0.4.3
[16] survival_2.41-3 latex2exp_0.4.0 magick_1.9 cowplot_0.9.3 ggpubr_0.1.7
[21] magrittr_1.5 gridExtra_2.3 rcompanion_2.0.0 ggsignif_0.4.0 ggplot2_3.1.0
[26] chron_2.3-52 lubridate_1.7.4 dplyr_0.7.5 kableExtra_0.9.0 knitr_1.20
[31] broom_0.4.5
loaded via a namespace (and not attached):
[1] minqa_1.2.4 colorspace_1.3-2 class_7.3-14 modeltools_0.2-22
[5] rprojroot_1.3-2 estimability_1.3 htmlTable_1.12 base64enc_0.1-3
[9] rstudioapi_0.7 MatrixModels_0.4-1 manipulate_1.0.1 coin_1.2-2
[13] xml2_1.2.0 codetools_0.2-15 mnormt_1.5-5 nloptr_1.0.4
[17] km.ci_0.5-2 cluster_2.0.7-1 readr_1.1.1 compiler_3.5.0
[21] httr_1.3.1 backports_1.1.2 assertthat_0.2.0 lazyeval_0.2.1
[25] quantreg_5.36 acepack_1.4.1 htmltools_0.3.6 tools_3.5.0
[29] coda_0.19-1 gtable_0.2.0 glue_1.3.0 reshape2_1.4.3
[33] Rcpp_1.0.0 nlme_3.1-137 psych_1.8.4 lmtest_0.9-36
[37] stringr_1.3.1 rvest_0.3.2 polspline_1.1.13 zoo_1.8-2
[41] scales_1.0.0 hms_0.4.2 parallel_3.5.0 sandwich_2.4-0
[45] expm_0.999-2 RColorBrewer_1.1-2 yaml_2.1.19 BSDA_1.2.0
[49] KMsurv_0.1-5 EMT_1.1 rpart_4.1-13 latticeExtra_0.6-28
[53] stringi_1.2.4 nortest_1.0-4 e1071_1.6-8 checkmate_1.8.5
[57] boot_1.3-20 rlang_0.3.0.1 pkgconfig_2.0.1 evaluate_0.10.1
[61] purrr_0.2.5 bindr_0.1.1 labeling_0.3 htmlwidgets_1.2
[65] cmprsk_2.2-7 tidyselect_0.2.4 plyr_1.8.4 R6_2.3.0
[69] DescTools_0.99.25 multcompView_0.1-7 pillar_1.2.3 foreign_0.8-70
[73] withr_2.1.2 nnet_7.3-12 tibble_1.4.2 survMisc_0.5.5
[77] rmarkdown_1.10 grid_3.5.0 data.table_1.11.4 digest_0.6.18
[81] xtable_1.8-2 tidyr_0.8.1 stats4_3.5.0 munsell_0.5.0
[85] viridisLite_0.3.0
Locale settings control character sets for input and output. You have
locale:
[1] C
but if you want to print non-ASCII characters such as ±, you'll need something such as UTF-8. One example of how to accomplish this (which seems to have solved your issue per the comments) is
Sys.setlocale("LC_ALL","en_US.UTF-8")
paste0("first_string", 2, "±", 3, "second_string", collapse = "")
which should output
[1] "first_string2±3second_string"
For further information, I'd check out the following sources as a starting point:
R help page for getting or setting the locale
RStudio support on character encoding
readr's locale vignette
I am using shape method in dtwclust package. When I run the following code:
data(uciCT)
hc.sbd <- tsclust(CharTraj, type = "hierarchical",
k = 20L, distance = "sbd",
preproc = zscore, centroid = shape_extraction,
seed = 320L)
I have the following error information:
Error in eigen(M) : LAPACK routines cannot be loaded
In addition: Warning message:
In eigen(M) :
unable to load shared object '//PAPER/fchen4/R/R-3.3.2/modules/x64/lapack.dll':
`maximal number of DLLs reached...
After I use library(mgcv), I have got:
Error in eigen(M) : LAPACK routines cannot be loaded
How can I fix this error? I have tried the answers in R lapack routines cannot be loaded. But they do not work for me. I have also updated all the packages. But still cannot work.
The information from sessionInfo() is:
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
locale:
[1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252 LC_MONETARY=English_Australia.1252 LC_NUMERIC=C
[5] LC_TIME=English_Australia.1252
attached base packages:
[1] parallel splines stats graphics grDevices utils datasets methods base
other attached packages:
[1] mgcv_1.8-17 nlme_3.1-131 dtwclust_3.1.2 dtw_1.18-1 clue_0.3-53
[6] ROSE_0.0-3 scatterplot3d_0.3-39 plot3D_1.1 ggrepel_0.6.5 pdfCluster_1.0-2
[11] pastecs_1.3-18 boot_1.3-18 geosphere_1.5-5 sp_1.2-4 XLConnect_0.2-12
[16] XLConnectJars_0.2-12 ica_1.0-1 visNetwork_1.0.3 igraph_1.0.1 Barnard_1.8
[21] Kendall_2.2 pspearman_0.3-0 FSelector_0.21 dunn.test_1.3.4 randomUniformForest_1.1.5
[26] dbscan_1.1-1 Hmisc_4.0-2 Formula_1.2-1 xgboost_0.6-4 doParallel_1.0.10
[31] iterators_1.0.8 foreach_1.4.3 corrplot_0.77 gbm_2.1.3 survival_2.41-3
[36] AppliedPredictiveModeling_1.1-6 e1071_1.6-8 mlbench_2.1-1 caret_6.0-73 lattice_0.20-35
[41] fpc_2.1-10 devtools_1.12.0 lubridate_1.6.0 ggmap_2.6.1 gridExtra_2.2.1
[46] leaflet_1.1.0 qdap_2.2.5 RColorBrewer_1.1-2 qdapTools_1.3.1 qdapRegex_0.6.0
[51] qdapDictionaries_1.0.6 stringr_1.2.0 xtable_1.8-2 tidyr_0.6.1 scales_0.4.1
[56] plotly_4.5.6 ggplot2_2.2.1 psych_1.7.3.21 mxnet_0.9.4 randomForest_4.6-12
[61] cluster_2.0.6 pROC_1.9.1 openxlsx_4.0.17 proxy_0.4-17 dplyr_0.5.0
[66] plyr_1.8.4
loaded via a namespace (and not attached):
[1] backports_1.0.5 lazyeval_0.2.0 entropy_1.2.1 openNLP_0.2-6 crosstalk_1.0.0 digest_0.6.12 htmltools_0.3.5 gender_0.5.1
[9] gdata_2.17.0 magrittr_1.5 checkmate_1.8.2 memoise_1.0.0 xlsx_0.5.7 tm_0.7-1 wordcloud_2.5 jpeg_0.1-8
[17] colorspace_1.3-2 RWeka_0.4-33 RCurl_1.95-4.8 jsonlite_1.4 lme4_1.1-12 registry_0.3 gtable_0.2.0 MatrixModels_0.4-1
[25] car_2.1-4 kernlab_0.9-25 prabclus_2.2-6 DEoptimR_1.0-8 maps_3.1.1 SparseM_1.76 mvtnorm_1.0-6 rngtools_1.2.4
[33] DBI_0.6-1 Rcpp_0.12.10 CORElearn_1.50.3 plotrix_3.6-4 viridisLite_0.2.0 htmlTable_1.9 magic_1.5-6 foreign_0.8-67
[41] mapproj_1.2-4 mclust_5.2.3 stats4_3.3.2 htmlwidgets_0.8 httr_1.2.1 acepack_1.4.1 modeltools_0.2-21 XML_3.98-1.6
[49] rJava_0.9-8 flexmix_2.3-13 openNLPdata_1.5.3-2 nnet_7.3-12 venneuler_1.1-0 reshape2_1.4.2 munsell_0.4.3 tools_3.3.2
[57] geometry_0.3-6 knitr_1.15.1 ModelMetrics_1.1.0 robustbase_0.92-7 caTools_1.17.1 purrr_0.2.2 RgoogleMaps_1.4.1 mime_0.5
[65] quantreg_5.29 slam_0.1-40 compiler_3.3.2 flexclust_1.3-4 pbkrtest_0.4-7 png_0.1-7 tibble_1.3.0 stringi_1.1.5
[73] trimcluster_0.1-2 Matrix_1.2-8 nloptr_1.0.4 RWekajars_3.9.1-3 data.table_1.10.4 bitops_1.0-6 httpuv_1.3.3 R6_2.2.0
[81] latticeExtra_0.6-28 codetools_0.2-15 reports_0.1.4 MASS_7.3-45 gtools_3.5.0 assertthat_0.1 chron_2.3-50 proto_1.0.0
[89] xlsxjars_0.6.1 pkgmaker_0.22 rjson_0.2.15 withr_1.0.2 mnormt_1.5-5 diptest_0.75-7 grid_3.3.2 rpart_4.1-10
[97] class_7.3-14 minqa_1.2.4 misc3d_0.8-4 NLP_0.1-10 shiny_1.0.1 base64enc_0.1-3