Rmarkdown not rendering .Rmd to pdf, pandoc error 2 - r

I was trying to render an Rmarkdown file to pdf using the beaverdown package and got the following error:
output file: thesis.knit.md
--chapters has been removed. Use --top-level-division=chapter instead. Try pandoc.exe --help for more information. Error: pandoc document
conversion failed with error 2 In addition: Warning message: In
has_crop_tools() : Tool(s) not installed or not in PATH: pdfcrop,
ghostcript
-> As a result, figure cropping will be disabled. Execution halted
I'm using:
Pandoc 2.11.4
MiKTeX 21.1
Session info:
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8.1 x64 (build 9600)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets
[6] methods base
loaded via a namespace (and not attached):
[1] pillar_1.4.7 compiler_4.0.3
[3] prettyunits_1.1.1 remotes_2.2.0
[5] tools_4.0.3 testthat_3.0.1
[7] digest_0.6.27 pkgbuild_1.2.0
[9] pkgload_1.1.0 gtable_0.3.0
[11] tibble_3.0.6 evaluate_0.14
[13] memoise_2.0.0 lifecycle_0.2.0
[15] pkgconfig_2.0.3 rlang_0.4.10
[17] DBI_1.1.0 cli_2.3.0
[19] yaml_2.2.1 xfun_0.20
[21] fastmap_1.1.0 withr_2.4.1
[23] dplyr_1.0.4 knitr_1.31
[25] generics_0.1.0 vctrs_0.3.6
[27] desc_1.2.0 fs_1.5.0
[29] devtools_2.3.2 grid_4.0.3
[31] tidyselect_1.1.0 rprojroot_2.0.2
[33] glue_1.4.2 R6_2.5.0
[35] processx_3.4.5 rmarkdown_2.6.6
[37] bookdown_0.21.6 sessioninfo_1.1.1
[39] ggplot2_3.3.3 blob_1.2.1
[41] callr_3.5.1 purrr_0.3.4
[43] magrittr_2.0.1 scales_1.1.1
[45] ps_1.5.0 ellipsis_0.3.1
[47] htmltools_0.5.1.1 usethis_2.0.0
[49] assertthat_0.2.1 colorspace_2.0-0
[51] tinytex_0.29 munsell_0.5.0
[53] cachem_1.0.3 beaverdown_0.2.1
[55] crayon_1.4.0
I haven't done anything besides rendering the template. Could this have anything to do with my current version of pandoc?
Any suggestion would be greatly appreciated.

Related

R studio just stops plotting - repeatedly, how to fix

I have a recurring problem where R studio just stops plotting. The code for plots works fine, as the plots are saving to file, but they just stop showing up in the plot pane.
Restarting the whole session seems to fix, but then I have to reload everything and it happens again almost immediately.
Would be grateful for any insight.
> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] RColorBrewer_1.1-2 pheatmap_1.0.12 stringr_1.4.0 gplots_3.1.1 viridis_0.5.1
[6] viridisLite_0.3.0 VennDiagram_1.6.20 futile.logger_1.4.3 tibble_3.0.5 fuzzyjoin_0.1.6
[11] ggthemes_4.2.4 tidyr_1.1.2 dplyr_1.0.3 data.table_1.13.6 readr_1.4.0
[16] ggVennDiagram_0.3 ggrepel_0.9.1 ggplot2_3.3.3 cowplot_1.1.1
loaded via a namespace (and not attached):
[1] gtools_3.8.2 tidyselect_1.1.0 purrr_0.3.4 sf_0.9-7 colorspace_2.0-0
[6] vctrs_0.3.6 generics_0.1.0 utf8_1.1.4 rlang_0.4.10 e1071_1.7-4
[11] pillar_1.4.7 glue_1.4.2 withr_2.4.0 DBI_1.1.1 lambda.r_1.2.4
[16] lifecycle_0.2.0 munsell_0.5.0 gtable_0.3.0 caTools_1.18.1 labeling_0.4.2
[21] class_7.3-17 fansi_0.4.2 Rcpp_1.0.6 KernSmooth_2.23-17 scales_1.1.1
[26] classInt_0.4-3 formatR_1.7 farver_2.0.3 gridExtra_2.3 digest_0.6.27
[31] hms_1.0.0 stringi_1.5.3 cli_2.2.0 tools_4.0.3 bitops_1.0-6
[36] magrittr_2.0.1 futile.options_1.0.1 crayon_1.3.4 pkgconfig_2.0.3 ellipsis_0.3.1
[41] assertthat_0.2.1 rstudioapi_0.13 R6_2.5.0 units_0.6-7 compiler_4.0.3

Error message in R (4.0.2) while using the filterandTrim function in dada2

Error message:
: Error in validObject(.Object) : invalid class “ScalarCharacter”
object: superclass "characterORconnection" not defined in the
environment of the object's class
I downloaded dada2 via biocManager.
The code is as follows (where all arguments are previously defined) :
out <- filterAndTrim(fnFs, filtFs, fnRs, filtRs, truncLen=250,
maxN=0, maxEE=1, truncQ=2, rm.phix=TRUE,
compress=TRUE, multithread=TRUE)
I was running into the same problem, also installing the package through biocManager.
After reading this long thread on GitHub where they also mention dada2, I tried to update R to its latest release, then I reinstalled BiocManager and dada2. Everything was running smoothly after that.
Session info WHEN I HAD PROBLEMS:
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] dada2_1.16.0 Rcpp_1.0.6
loaded via a namespace (and not attached):
[1] SummarizedExperiment_1.18.2 tidyselect_1.1.1 purrr_0.3.4
[4] reshape2_1.4.4 lattice_0.20-41 colorspace_2.0-1
[7] vctrs_0.3.8 generics_0.1.0 stats4_4.0.3
[10] utf8_1.2.1 rlang_0.4.11 pillar_1.6.1
[13] glue_1.4.2 DBI_1.1.1 BiocParallel_1.22.0
[16] BiocGenerics_0.38.0 RColorBrewer_1.1-2 matrixStats_0.59.0
[19] jpeg_0.1-8.1 GenomeInfoDbData_1.2.4 lifecycle_1.0.0
[22] plyr_1.8.6 stringr_1.4.0 zlibbioc_1.36.0
[25] Biostrings_2.58.0 munsell_0.5.0 gtable_0.3.0
[28] hwriter_1.3.2 labeling_0.4.2 latticeExtra_0.6-29
[31] Biobase_2.48.0 IRanges_2.24.1 GenomeInfoDb_1.26.7
[34] parallel_4.0.3 fansi_0.5.0 scales_1.1.1
[37] BiocManager_1.30.16 DelayedArray_0.14.1 S4Vectors_0.28.1
[40] RcppParallel_5.1.4 XVector_0.30.0 ShortRead_1.46.0
[43] farver_2.1.0 Rsamtools_2.4.0 digest_0.6.27
[46] ggplot2_3.3.5 png_0.1-7 stringi_1.5.3
[49] dplyr_1.0.7 GenomicRanges_1.40.0 grid_4.0.3
[52] tools_4.0.3 bitops_1.0-7 magrittr_2.0.1
[55] RCurl_1.98-1.3 tibble_3.1.2 crayon_1.4.1
[58] pkgconfig_2.0.3 ellipsis_0.3.2 Matrix_1.2-18
[61] assertthat_0.2.1 rstudioapi_0.13 R6_2.5.0
[64] GenomicAlignments_1.24.0 compiler_4.0.3
Session info WITHOUT PROBLEMS:
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] dada2_1.20.0 Rcpp_1.0.6
loaded via a namespace (and not attached):
[1] SummarizedExperiment_1.22.0 tidyselect_1.1.1 reshape2_1.4.4 purrr_0.3.4
[5] lattice_0.20-44 colorspace_2.0-2 vctrs_0.3.8 generics_0.1.0
[9] stats4_4.1.0 utf8_1.2.1 rlang_0.4.11 pillar_1.6.1
[13] glue_1.4.2 DBI_1.1.1 BiocParallel_1.26.1 BiocGenerics_0.38.0
[17] RColorBrewer_1.1-2 plyr_1.8.6 matrixStats_0.59.0 jpeg_0.1-8.1
[21] GenomeInfoDbData_1.2.6 lifecycle_1.0.0 stringr_1.4.0 zlibbioc_1.38.0
[25] MatrixGenerics_1.4.0 Biostrings_2.60.1 munsell_0.5.0 gtable_0.3.0
[29] hwriter_1.3.2 latticeExtra_0.6-29 Biobase_2.52.0 IRanges_2.26.0
[33] GenomeInfoDb_1.28.1 parallel_4.1.0 fansi_0.5.0 scales_1.1.1
[37] DelayedArray_0.18.0 S4Vectors_0.30.0 RcppParallel_5.1.4 XVector_0.32.0
[41] ShortRead_1.50.0 Rsamtools_2.8.0 ggplot2_3.3.5 png_0.1-7
[45] stringi_1.6.2 dplyr_1.0.7 GenomicRanges_1.44.0 grid_4.1.0
[49] tools_4.1.0 bitops_1.0-7 magrittr_2.0.1 RCurl_1.98-1.3
[53] tibble_3.1.2 crayon_1.4.1 pkgconfig_2.0.3 ellipsis_0.3.2
[57] Matrix_1.3-4 assertthat_0.2.1 rstudioapi_0.13 R6_2.5.0
[61] GenomicAlignments_1.28.0 compiler_4.1.0

What is causing this error: "Failed to retrieve package sources for XML"

What is causing this error: "Failed to retrieve package sources for XML"? I'm trying to publish an example dashboard to R Connect.
[Connect] 2020/12/10 16:40:00.827991448 Error in getSourceForPkgRecord(pkgRecord, srcDir(project), availablePackagesSource(repos = repos), : Failed to retrieve package sources for XML 3.99-0.5 from CRAN (internet connectivity issue?) [3.99-0.3 is current]
[Connect] Build error: A required R package was found in the package repository, but the specified version is not available. (r-package-version-not-available)
Application deployment failed with error: A required R package was found in the package repository, but the specified version is not available. (r-package-version-not-available)
I tried removing and then reinstalling XLM and recently updated my R to version 4.0.3. Wondering if that means I need to deprecate down to 3.99 for XML?
Repo info
> options('repos')
$repos
CRAN
"https://cran.rstudio.com/"
attr(,"RStudio")
[1] TRUE
Session info
> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
Random number generation:
RNG: Mersenne-Twister
Normal: Inversion
Sample: Rounding
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] shinydashboard_0.7.1 PerformanceAnalytics_2.0.4 xts_0.12.1
[4] zoo_1.8-8 highcharter_0.8.2 ggplot2_3.3.2
[7] dygraphs_1.1.1.6 dplyr_1.0.2 shiny_1.5.0
loaded via a namespace (and not attached):
[1] tidyselect_1.1.0 purrr_0.3.4 lattice_0.20-41 colorspace_2.0-0 vctrs_0.3.5
[6] generics_0.1.0 htmltools_0.5.0 yaml_2.2.1 rlang_0.4.9 later_1.1.0.1
[11] pillar_1.4.7 glue_1.4.2 withr_2.3.0 TTR_0.24.2 lifecycle_0.2.0
[16] quantmod_0.4.18 stringr_1.4.0 munsell_0.5.0 gtable_0.3.0 htmlwidgets_1.5.2
[21] labeling_0.4.2 fastmap_1.0.1 Cairo_1.5-12.2 httpuv_1.5.4 curl_4.3
[26] broom_0.7.2 Rcpp_1.0.5 xtable_1.8-4 openssl_1.4.3 promises_1.1.1
[31] scales_1.1.1 backports_1.2.0 jsonlite_1.7.1 farver_2.0.3 mime_0.9
[36] askpass_1.1 digest_0.6.27 stringi_1.5.3 rlist_0.4.6.1 grid_4.0.3
[41] quadprog_1.5-8 tools_4.0.3 magrittr_2.0.1 tibble_3.0.4 crayon_1.3.4
[46] tidyr_1.1.2 pkgconfig_2.0.3 ellipsis_0.3.1 rsconnect_0.8.16 data.table_1.13.4
[51] lubridate_1.7.9.2 assertthat_0.2.1 rstudioapi_0.13 R6_2.5.0 igraph_1.2.6
[56] compiler_4.0.3

RStudio Viewer Error: "session/viewhtml...." not found

I recently installed a daily build version of R Studio, 1.4.671. Since that installation, anything that runs in the viewer (e.g. gt or lavaanPlot) gives me an error like this:
/session/viewhtml528813ce72d/index.html?viewer_pane=1&capabilities=1&host=http%3A%2F%2F127.0.0.1%3A27742 not found
I have fully uninstalled 1.4.671, restarted my computer, and reinstalled the version that worked this morning, 1.3.1056. Not sure
This is becoming quite a problem because I am not able to easily see any model coefficients that I am currently working on (in a neat way, they are messy in the console).
I have also reset RStudio's state following https://support.rstudio.com/hc/en-us/articles/200534577-Resetting-RStudio-s-State and removed my .Renviron file.
Update: if the error shows but I choose to export as HTML, the HTML file works.
Update2: both running Shiny and knitting an RMarkdown document to HTML works. It's just displaying something inside RStudio's viewer that is causing issues.
R version 4.0.0 (2020-04-24)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
other attached packages:
[1] gt_0.2.1 patchwork_1.0.0 waffle_1.0.1
[4] plotly_4.9.2.1 ggstance_0.3.4 ggridges_0.5.2
[7] foreign_0.8-78 gghighlight_0.3.0 gridExtra_2.3
[10] readxl_1.3.1 emmeans_1.4.7 broom_0.5.6
[13] fastDummies_1.6.1 modelsummary_0.5.0 tables_0.9.3
[16] gtsummary_1.3.2 janitor_2.0.1 haven_2.3.1
[19] forcats_0.5.0 stringr_1.4.0 dplyr_1.0.0
[22] purrr_0.3.4 readr_1.3.1 tidyr_1.1.0
[25] tibble_3.0.1 ggplot2_3.3.1 tidyverse_1.3.0
loaded via a namespace (and not attached):
[1] nlme_3.1-147 fs_1.4.1 lubridate_1.7.8
[4] RColorBrewer_1.1-2 httr_1.4.1 tools_4.0.0
[7] backports_1.1.7 DT_0.13 R6_2.4.1
[10] DBI_1.1.0 lazyeval_0.2.2 colorspace_1.4-1
[13] withr_2.2.0 tidyselect_1.1.0 extrafontdb_1.0
[16] curl_4.3 compiler_4.0.0 cli_2.0.2
[19] rvest_0.3.5 xml2_1.3.2 sandwich_2.5-1
[22] labeling_0.3 sass_0.2.0 scales_1.1.1
[25] checkmate_2.0.0 mvtnorm_1.1-0 commonmark_1.7
[28] digest_0.6.25 rmarkdown_2.2 pkgconfig_2.0.3
[31] htmltools_0.5.0 extrafont_0.17 dbplyr_1.4.4
[34] htmlwidgets_1.5.1 rlang_0.4.6 rstudioapi_0.11
[37] farver_2.0.3 generics_0.0.2 zoo_1.8-8
[40] jsonlite_1.6.1 magrittr_1.5 Matrix_1.2-18
[43] Rcpp_1.0.4.6 munsell_0.5.0 fansi_0.4.1
[46] lifecycle_0.2.0 stringi_1.4.6 multcomp_1.4-13
[49] yaml_2.2.1 snakecase_0.11.0 MASS_7.3-51.5
[52] plyr_1.8.6 grid_4.0.0 blob_1.2.1
[55] crayon_1.3.4 lattice_0.20-41 splines_4.0.0
[58] hms_0.5.3 knitr_1.28 pillar_1.4.4
[61] estimability_1.3 codetools_0.2-16 reprex_0.3.0
[64] glue_1.4.1 packrat_0.5.0 evaluate_0.14
[67] data.table_1.12.8 modelr_0.1.8 vctrs_0.3.0
[70] Rttf2pt1_1.3.8 cellranger_1.1.0 gtable_0.3.0
[73] assertthat_0.2.1 xfun_0.14 xtable_1.8-4
[76] coda_0.19-3 survival_3.1-12 viridisLite_0.3.0
[79] TH.data_1.0-10 ellipsis_0.3.1
>

opts_knit$set(root.dir = ) working in knit but not chunks

I have a Rmd file saved in a folder one below my project([path]/scripts), and the data is in a parallel folder ([path]/data) and I can't seem to set the working directory and access the data when running the chunks. I use the setup chunk, as below, and then run code in a following chunk. If I knit the whole document it works fine but if I run the 2nd chunk on its own I get "Error: 'data/warriner_2013_emotional_valence.csv' does not exist in current working directory ('[path]/scripts')" Can anyone help out with what I'm doing wrong?
```{r setup, include=FALSE}
require("knitr")
opts_chunk$set(echo = TRUE)
opts_knit$set(root.dir = "..")
```
```{r}
library(tidyverse)
war <- read_csv('data/warriner_2013_emotional_valence.csv')
```
Other solutions I've found say to run the code in a separate chunk to the setup, which I'm doing.
I've also tried changing the R Markdown Global Options "Evaluate chunks in directory: 'Project'" - which has no effect.
>sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils
[5] datasets methods base
other attached packages:
[1] broom_0.7.0 forcats_0.5.0
[3] stringr_1.4.0 dplyr_1.0.1
[5] purrr_0.3.4 readr_1.3.1
[7] tidyr_1.1.1 tibble_3.0.3
[9] ggplot2_3.3.2 tidyverse_1.3.0
[11] knitr_1.29
loaded via a namespace (and not attached):
[1] Rcpp_1.0.5 cellranger_1.1.0
[3] pillar_1.4.6 compiler_4.0.2
[5] dbplyr_1.4.4 tools_4.0.2
[7] digest_0.6.25 lubridate_1.7.9
[9] jsonlite_1.7.0 evaluate_0.14
[11] lifecycle_0.2.0 gtable_0.3.0
[13] pkgconfig_2.0.3 rlang_0.4.7
[15] reprex_0.3.0 cli_2.0.2
[17] DBI_1.1.0 rstudioapi_0.11
[19] yaml_2.2.1 haven_2.3.1
[21] xfun_0.16 withr_2.2.0
[23] xml2_1.3.2 httr_1.4.2
[25] fs_1.5.0 generics_0.0.2
[27] vctrs_0.3.2 hms_0.5.3
[29] grid_4.0.2 tidyselect_1.1.0
[31] glue_1.4.1 R6_2.4.1
[33] fansi_0.4.1 readxl_1.3.1
[35] rmarkdown_2.3 modelr_0.1.8
[37] blob_1.2.1 magrittr_1.5
[39] backports_1.1.7 scales_1.1.1
[41] ellipsis_0.3.1 htmltools_0.5.0
[43] rvest_0.3.6 assertthat_0.2.1
[45] colorspace_1.4-1 stringi_1.4.6
[47] munsell_0.5.0 crayon_1.3.4
I ran into the same issue. What worked for me was not to use opts_knit$set(root.dir = "../"). Instead I set Tools -> Global Options -> Rmarkdown to Project.

Resources