Can't load libraries on any renv project. How to fix this?

70 views Asked by At

Today I opened an R project I was working on yesterday, and suddenly found I was unable to load ggplot2. I've found the same problem with all my projects.

As an example, I created a new RStudio project and installed the sole package ggplot2. I ran all these commands successfully:

renv::init()
install.packages("ggplot2")
renv::snapshot()

ggplot2 is duly recorded in renv.lock but library(ggplot2) throws the following error:

Error: package or namespace load failed for ‘ggplot2’ in namespaceExport(ns, exports):
 undefined exports: ContinuousRange, DiscreteRange, Range, abs_area, alpha, area_pal, as.trans, asn_trans, atanh_trans, boxcox_trans, breaks_extended, breaks_log, breaks_pretty, breaks_width, brewer_pal, cbreaks, censor, col2hcl, col_bin, col_factor, col_numeric, col_quantile, colour_ramp, comma, comma_format, compose_trans, cscale, cut_long_scale, cut_short_scale, cut_si, date_breaks, date_format, date_trans, demo_continuous, demo_datetime, demo_discrete, demo_log10, demo_time, dichromat_pal, discard, div_gradient_pal, dollar, dollar_format, dscale, exp_trans, expand_range, extended_breaks, format_format, fullseq, gradient_n_pal, grey_pal, hms_trans, hue_pal, identity_pal, identity_trans, is.trans, label_bytes, label_comma, label_date, label_date_short, label_dollar, label_log, label_math, label_number, label_number_auto, label_number_si, label_ordinal, label_parse, label_percent, label_pvalue, 
In addition: Warning message:
S3 methods ‘fullseq.Date’, ‘fullseq.POSIXt’, ‘fullseq.difftime’, ‘fullseq.numeric’, ‘lines.trans’, ‘offset_by.Date’, ‘offset_by.POSIXt’, ‘offset_by.difftime’, ‘offset_by.numeric’, ‘plot.trans’, ‘print.trans’, ‘rescale.NULL’, ‘rescale.Date’, ‘rescale.POSIXt’, ‘rescale.dist’, ‘rescale.integer64’, ‘rescale.logical’, ‘rescale.numeric’, ‘rescale_mid.NULL’, ‘rescale_mid.Date’, ‘rescale_mid.POSIXt’, ‘rescale_mid.dist’, ‘rescale_mid.integer64’, ‘rescale_mid.logical’, ‘rescale_mid.numeric’, ‘round_any.POSIXct’, ‘round_any.numeric’ were declared in NAMESPACE but not found 

Despite extensive searches I can't find users reporting similar issues. I suspect this could be something to do with renv's cache, R's system/user libraries on my local machines, or the fact that my R projects are stored on OneDrive which frequently causes merge and sync issues.

But I have no idea what the solution might be. Can anybody help?

1

There are 1 answers

1
Tom Wagstaff On BEST ANSWER

I eventually discovered this post on Posit Community and as suggested there ran renv::rebuild() in my test project, which fixed it.

To my surprise, some of my other projects then started working too without the need to run renv::rebuild() again. Others needed rebuilding separately.

All of this makes me think that SharePoint/OneDrive sync shenanigans may be to blame, but I'm still very confused about the cause and the solution so still worth answering this if you have an idea!