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

Chris Evans chr|@ho|d @end|ng |rom p@yctc@org
Fri Aug 25 11:49:03 CEST 2023

On 24/08/2023 21:05, Duncan Murdoch wrote:
> On 24/08/2023 1:58 p.m., Chris Evans via R-help wrote:
>> 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
> 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?

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.

> 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.
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!


> Duncan Murdoch
[rest snipped]

Chris Evans (he/him)
Visiting Professor, UDLA, Quito, Ecuador & Honorary Professor, 
University of Roehampton, London, UK.
Work web site: https://www.psyctc.org/psyctc/
CORE site: http://www.coresystemtrust.org.uk/
Personal site: https://www.psyctc.org/pelerinage2016/

More information about the R-help mailing list