[R] Cacheing of functions from libraries other than the base in Rmarkdown
chr|@ @end|ng |rom p@yctc@org
Sun Sep 19 19:49:26 CEST 2021
[Damn: now I'm forgetting that r-help has reply-to the individual respondent,
sorry for duplicate Email Charles but I'm sure this should be in the archives.]
Excellent: I'm sure that's it. I hadn't noticed that I'd loaded libraries in a
cached code block. I thought I'd learned not to do that: can't believe I didn't
Thanks, another hole in a foot: (re)-read the pertinent manual before assuming
something is broken Christopher!
Very best all,
----- Original Message -----
> From: "Berry, Charles" <ccberry using health.ucsd.edu>
> To: "Chris Evans" <chrishold using psyctc.org>
> Cc: "R-help" <R-help using r-project.org>
> Sent: Sunday, 19 September, 2021 19:28:49
> Subject: Re: Cacheing of functions from libraries other than the base in Rmarkdown
>> On Sep 18, 2021, at 12:26 PM, Chris Evans <chrishold using psyctc.org> wrote:
>> This question may belong somewhere else, if so, please signpost me and accept
>> What is happening is that I have a large (for me, > 3k lines) Rmarkdown file
>> with many R code blocks (no other code or
>> engine is used) working on some large datasets. I have some inline r like
>> There are `r n_distinct(tibDat$ID)` participants and `r nrow(tibDat)` rows of
>> What I am finding is that even if one knit has worked fine and I change
>> something somewhere and knit again, the second
>> knit is often failing with an error like
>> n_distinct(tibDat$ID) : could not find function "n_distinct"
>> This is not happening for functions like nrow() from base R and it mostly seems
>> to happen to functions from the tidyverse.
>> I think what is happening is some sort of cache corruption presumably caused by
>> the memory demands. I am pretty sure I've
>> seen this before but a long time ago and dealt with it by deleting the files and
>> cache folders created by the knit.
> Caching things that depend on libraries is known to be tricky.
> Specifically, it is advised that "loading packages via library() in a cached
> chunk and these packages will be used by uncached chunks" is something you
> should not do. I suspect that this is the problem with your inline chunk.
> I have to reread things like:
> and relevant parts of the manual to be sure I didn't mess something up and maybe
> you should look at that and the manual yet another time.
Chris Evans (he/him) <chris using psyctc.org> Visiting Professor, University of Sheffield and UDLA, Quito, Ecuador
I do some consultation work for the University of Roehampton <chris.evans using roehampton.ac.uk> and other places
but <chris using psyctc.org> remains my main Email address. I have a work web site at:
and a site I manage for CORE and CORE system trust at:
I have "semigrated" to France, see:
If you want an Emeeting, I am trying to keep them to Thursdays and my diary is at:
Beware: French time, generally an hour ahead of UK.
[[alternative HTML version deleted]]
More information about the R-help