Skip to content

Error "STRING_ELT() can only be applied to a 'character vector', not a 'list'" from rmarkdown

7 messages · Duncan Murdoch, Chris Evans, Ivan Krylov

#
I have an Rmarkdown file which is part of my distill "Rblog" 
(https://www.psyctc.org/Rblog/).? It was knitting fine until last week,
now knitting terminates with this:

Rscript -e 'rmarkdown::render("creating-a-shiny-server.Rmd")'


processing file: creating-a-shiny-server.Rmd

output file: creating-a-shiny-server.knit.md

/usr/bin/pandoc +RTS -K512m -RTS creating-a-shiny-server.knit.md --to 
html5 --from markdown+autolink_bare_uris+tex_math_single_backslash 
--output creating-a-shiny-server.html --lua-filter 
/home/chris/R/x86_64-pc-linux-gnu-library/4.3/rmarkdown/rmarkdown/lua/pagebreak.lua 
--lua-filter 
/home/chris/R/x86_64-pc-linux-gnu-library/4.3/rmarkdown/rmarkdown/lua/latex-div.lua 
--wrap preserve --standalone --table-of-contents --toc-depth 4 
--variable toc-float=1 --highlight-style 
/home/chris/R/x86_64-pc-linux-gnu-library/4.3/distill/rmarkdown/templates/distill_article/resources/arrow.theme 
--template 
/home/chris/R/x86_64-pc-linux-gnu-library/4.3/distill/rmarkdown/templates/distill_article/resources/default.html 
'--metadata=link-citations:true' --include-in-header 
/tmp/Rtmp7WHAIE/fileb39b179ffd801html --include-in-header 
/tmp/Rtmp7WHAIE/fileb39b15b1e3532html --include-in-header 
/tmp/Rtmp7WHAIE/fileb39b13239652chtml --include-in-header 
/tmp/Rtmp7WHAIE/fileb39b1581627e8html --include-in-header 
/tmp/Rtmp7WHAIE/fileb39b12850a405html --include-before-body 
/tmp/Rtmp7WHAIE/fileb39b16f8d72a6html --include-before-body 
/tmp/Rtmp7WHAIE/fileb39b16ce17d77html --include-before-body 
/tmp/Rtmp7WHAIE/fileb39b12f851f86html --include-after-body 
/tmp/Rtmp7WHAIE/fileb39b14447b7b1html --include-after-body 
/tmp/Rtmp7WHAIE/fileb39b143ff6632html --include-after-body 
/tmp/Rtmp7WHAIE/fileb39b1345b1dddhtml --mathjax --variable 
'mathjax-url=https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' 
--include-in-header /tmp/Rtmp7WHAIE/rmarkdown-strb39b160f391de.html 
--include-in-header /tmp/Rtmp7WHAIE/fileb39b164361476html
Error in `xml_text<-.xml_node`(`*tmp*`, value = text) :
 ? STRING_ELT() can only be applied to a 'character vector', not a 'list'
Calls: <Anonymous> ... write_feed_xml -> add_child -> <Anonymous> -> 
xml_text<-.xml_node
In addition: There were 20 warnings (use warnings() to see them)
Execution halted

It's the same if I do it in Rstudio or from the command line like that 
so I think I can safely say it's not an Rstudio issue.

The same happens with other Rmd files in the distill _posts directory.

The really weird aspects are:

1) the html _is_ created fine (but if running in Rstudio it doesn't 
transfer to showing you the html)

2) the error message is only there if I run the Rmd in that directory, 
i.e. the 2023-08-19-creating-a-shiny-server directory in
_posts or in _posts above that, but I move it up againif I move it to 
higher or other directories it works fine:

Rscript -e 'rmarkdown::render("creating-a-shiny-server.Rmd")'


processing file: creating-a-shiny-server.Rmd

output file: creating-a-shiny-server.knit.md

/usr/bin/pandoc +RTS -K512m -RTS creating-a-shiny-server.knit.md --to 
html5 --from markdown+autolink_bare_uris+tex_math_single_backslash 
--output creating-a-shiny-server.html --lua-filter 
/home/chris/R/x86_64-pc-linux-gnu-library/4.3/rmarkdown/rmarkdown/lua/pagebreak.lua 
--lua-filter 
/home/chris/R/x86_64-pc-linux-gnu-library/4.3/rmarkdown/rmarkdown/lua/latex-div.lua 
--wrap preserve --standalone --table-of-contents --toc-depth 4 
--variable toc-float=1 --highlight-style 
/home/chris/R/x86_64-pc-linux-gnu-library/4.3/distill/rmarkdown/templates/distill_article/resources/arrow.theme 
--template 
/home/chris/R/x86_64-pc-linux-gnu-library/4.3/distill/rmarkdown/templates/distill_article/resources/default.html 
'--metadata=link-citations:true' --include-in-header 
/tmp/RtmpGMqTCm/fileb43a436c6281fhtml --include-in-header 
/tmp/RtmpGMqTCm/fileb43a455b7e5bdhtml --include-in-header 
/tmp/RtmpGMqTCm/fileb43a461db1ea1html --include-in-header 
/tmp/RtmpGMqTCm/fileb43a474a6e703html --include-before-body 
/tmp/RtmpGMqTCm/fileb43a494bd34html --include-before-body 
/tmp/RtmpGMqTCm/fileb43a42fbfec67html --include-before-body 
/tmp/RtmpGMqTCm/fileb43a4273d84ebhtml --include-after-body 
/tmp/RtmpGMqTCm/fileb43a4725e33cahtml --include-after-body 
/tmp/RtmpGMqTCm/fileb43a43d386888html --include-after-body 
/tmp/RtmpGMqTCm/fileb43a43f19b459html --mathjax --variable 
'mathjax-url=https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' 
--include-in-header /tmp/RtmpGMqTCm/rmarkdown-strb43a43033daa0.html 
--include-in-header /tmp/RtmpGMqTCm/fileb43a42807e405html

Output created: creating-a-shiny-server.html
Warning message:
In as.character.POSIXt(as.POSIXlt(x), ...) :
 ? as.character(td, ..) no longer obeys a 'format' argument; use 
format(td, ..) ?

The 20 warnings are:

 > warnings()
Warning messages:
1: In as.character.POSIXt(as.POSIXlt(x), ...) :
 ? as.character(td, ..) no longer obeys a 'format' argument; use 
format(td, ..) ?
2: In as.character.POSIXt(as.POSIXlt(x), ...) :
 ? as.character(td, ..) no longer obeys a 'format' argument; use 
format(td, ..) ?
3: In as.character.POSIXt(as.POSIXlt(x), ...) :
 ? as.character(td, ..) no longer obeys a 'format' argument; use 
format(td, ..) ?
4: In as.character.POSIXt(as.POSIXlt(x), ...) :
 ? as.character(td, ..) no longer obeys a 'format' argument; use 
format(td, ..) ?
5: In as.character.POSIXt(as.POSIXlt(x), ...) :
 ? as.character(td, ..) no longer obeys a 'format' argument; use 
format(td, ..) ?
6: In as.character.POSIXt(as.POSIXlt(x), ...) :
 ? as.character(td, ..) no longer obeys a 'format' argument; use 
format(td, ..) ?
7: In as.character.POSIXt(as.POSIXlt(x), ...) :
 ? as.character(td, ..) no longer obeys a 'format' argument; use 
format(td, ..) ?
8: In as.character.POSIXt(as.POSIXlt(x), ...) :
 ? as.character(td, ..) no longer obeys a 'format' argument; use 
format(td, ..) ?
9: In as.character.POSIXt(as.POSIXlt(x), ...) :
 ? as.character(td, ..) no longer obeys a 'format' argument; use 
format(td, ..) ?
10: In as.character.POSIXt(as.POSIXlt(x), ...) :
 ? as.character(td, ..) no longer obeys a 'format' argument; use 
format(td, ..) ?
11: In as.character.POSIXt(as.POSIXlt(x), ...) :
 ? as.character(td, ..) no longer obeys a 'format' argument; use 
format(td, ..) ?
12: In as.character.POSIXt(as.POSIXlt(x), ...) :
 ? as.character(td, ..) no longer obeys a 'format' argument; use 
format(td, ..) ?
13: In as.character.POSIXt(as.POSIXlt(x), ...) :
 ? as.character(td, ..) no longer obeys a 'format' argument; use 
format(td, ..) ?
14: In as.character.POSIXt(as.POSIXlt(x), ...) :
 ? as.character(td, ..) no longer obeys a 'format' argument; use 
format(td, ..) ?
15: In as.character.POSIXt(as.POSIXlt(x), ...) :
 ? as.character(td, ..) no longer obeys a 'format' argument; use 
format(td, ..) ?
16: In as.character.POSIXt(as.POSIXlt(x), ...) :
 ? as.character(td, ..) no longer obeys a 'format' argument; use 
format(td, ..) ?
17: In as.character.POSIXt(as.POSIXlt(x), ...) :
 ? as.character(td, ..) no longer obeys a 'format' argument; use 
format(td, ..) ?
18: In as.character.POSIXt(as.POSIXlt(x), ...) :
 ? as.character(td, ..) no longer obeys a 'format' argument; use 
format(td, ..) ?
19: In as.character.POSIXt(as.POSIXlt(x), ...) :
 ? as.character(td, ..) no longer obeys a 'format' argument; use 
format(td, ..) ?
20: In as.character.POSIXt(as.POSIXlt(x), ...) :
 ? as.character(td, ..) no longer obeys a 'format' argument; use 
format(td, ..) ?

I'm not convinced that they're related to this as we know that's a issue 
that fixed and making its way to CRAN and is only
a warning.

I'm using up to date R on up to date Ubuntu 22.04.3 LTS.

 > sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.3 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/libopenblasp-r0.3.20.so; 
LAPACK version 3.10.0

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

time zone: Europe/Paris
tzcode source: system (glibc)

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

other attached packages:
 ?[1] lubridate_1.9.2 forcats_1.0.0?? stringr_1.5.0 dplyr_1.1.2
 ?[5] purrr_1.0.2???? readr_2.1.4???? tidyr_1.3.0 tibble_3.2.1
 ?[9] ggplot2_3.4.3?? tidyverse_2.0.0

loaded via a namespace (and not attached):
 ?[1] sass_0.4.7??????? utf8_1.2.3??????? generics_0.1.3 xml2_1.3.5
 ?[5] stringi_1.7.12??? distill_1.5?????? hms_1.1.3 digest_0.6.33
 ?[9] magrittr_2.0.3??? evaluate_0.21???? grid_4.3.1 timechange_0.2.0
[13] bookdown_0.35???? fastmap_1.1.1???? rprojroot_2.0.3 jsonlite_1.8.7
[17] fansi_1.0.4?????? scales_1.2.1????? jquerylib_0.1.4 cli_3.6.1
[21] rlang_1.1.1?????? munsell_0.5.0???? withr_2.5.0 cachem_1.0.8
[25] yaml_2.3.7??????? tools_4.3.1?????? tzdb_0.4.0 memoise_2.0.1
[29] colorspace_2.1-0? mime_0.12???????? vctrs_0.6.3 R6_2.5.1
[33] png_0.1-8???????? lifecycle_1.0.3?? fontawesome_0.5.2 pkgconfig_2.0.3
[37] pillar_1.9.0????? bslib_0.5.1?????? gtable_0.3.4 glue_1.6.2
[41] xfun_0.40???????? tidyselect_1.2.0? highr_0.10 rstudioapi_0.15.0
[45] knitr_1.43??????? farver_2.1.1????? htmltools_0.5.6 rmarkdown_2.24
[49] labeling_0.4.2??? compiler_4.3.1??? downlit_0.4.3

Really bizarre issue but it's crippling my developing the Distill blog 
further as it breaks the otherwise excellent
Rstudio edit/knit/review/edit/knit/review workflow I use.

Appreciate any suggestions: TIA,


Chris
#
Could you post a link to the source for that Rmd file?

Duncan Murdoch
On 24/08/2023 1:58 p.m., Chris Evans via R-help wrote:
#
On 24/08/2023 1:58 p.m., Chris Evans via R-help wrote:
That function `xml_text<-.xml_node` is in the xml2 package, which was 
updated in early July.  Do you think the error has been happening since 
you updated your copy, or did something else trigger it?

One way to debug this is as follows.  With the file in the directory 
where the error occurs, start R (or RStudio, it shouldn't matter), and run

   debug(xml2:::`xml_text<-.xml_node`)
   rmarkdown::render("creating-a-shiny-server.Rmd")

If you're lucky, the error will happen on the first call to that 
function, and you can trace into it to see what's so weird.  If you're 
unlucky, it will happen after many calls.  Then you'll probably have to 
use trace() to identify which call causes problems (increment and print 
a counter on each call), then break just before the bad call and try to 
see what went wrong.

Duncan Murdoch
#
On 24/08/2023 21:05, Duncan Murdoch wrote:
I wish I had good clues from that. Everything with the "blog" was 
working fine until the 21st. Since then (yesterday) I have fixed an 
issue (down to the mirror.infomaniak.ch server I was using)
that had meant a lot of my Ubuntu packages were out of date but this 
problem started before I fixed that, by the 23rd.? I update the OS daily 
(but that wasn't working for deb packages until yesterday
because of the mirror problem) and I also R packages daily but I don't 
watch what updates and what doesn't.? I guess I could put that on a cron 
job with an Email to self to keep track of it in future.
Hm.? I tried that butI really don't know what to make of what it's 
telling me.? It seemed to me that I was just stepping through the same 
bits of code (with the warning that the debugger didn't
have the source so I'm not really sure what it was showing me!) Sorry, 
showing my ignorance of that level of R debugging.? Can you give me any 
more advice about that?? Or perhaps _if_ the code
does give the same error for you, you'd be able to see quickly what I can't?

Deeply grateful for the help and sorry I'm not up to scratch on my 
side.? I'd really appreciate any other thoughts as I'm stuck with the 
blog for now!

Chris
[rest snipped]
#
? Fri, 25 Aug 2023 11:49:03 +0200
Chris Evans via R-help <r-help at r-project.org> ?????:
write_feed_xml is an internal function in the "distill" package. It's
supposed to create the RSS feed for a whole set of web pages. Somehow
it ends up trying to assign a list to xml2::xml_text(some_xml_node),
where only assigning a character string would make sense.

The function contains quite a lot of assignments like this. Some of
them come from site_config (which comes from _site.yml?), others are
taken from the article contents and metadata.

If you run options(error = recover) in a fresh R session before
knitting your website, you should get a debugger menu right at the
point where the code crashes. Try to find out what is the XML node
where the text is being assigned and what is the list that ends up
being assigned into it. You will also get the option to see the
variables in the callers of the failing function, which may shed some
light on the situation too.
#
Fascinating and, as ever, extremely helpful Ivan.? Duncan Murdoch nudged 
me in the right direction and for now
the solution for me is that if I don't have the lines:

description: |
 ? CE's pages "blog posts" about using R

in _site.yaml that have been there for ages, then everything works.? If 
I put _anything_ in there, including
two lines copied and pasted from a brand new distill site instead of 
those two lines then the error returns
so I think something else is awry in my main distill site that has 
rendered the knitting of the site
allergic to having a description in _site.yaml.? I should probably go 
further to try to debug this but across
this and the trouble I was having with the mirror.infomaniak.ch ubuntu 
mirror (R-sig-Debian thread, another
you helped with, has details of that!) I have lost too much time 
debugging in the last week and desperately
need to get back to my main work (and work I'm more competent to do!)

Many thanks again,

Chris
On 25/08/2023 15:48, Ivan Krylov wrote: