Error in identicalUnits(x) : object is not a unit

Hello,
When I run a ggplot I am getting an error message of "Error in identicalUnits(x) : object is not a unit”

I Updated RStudio as well as a few other packages (Tidyverse, Data Tables, more) today and I’m not sure if the error I’m getting is a result of the packages or R Studio.

Plotting worked earlier and previously. When I run the same code on my MacBook Pro (running RStudio 2022.12.0+353) it works without an error. Also if I run the same code in a Quarto document, it plots as expected without generating an error.

Here is my sample dataframe (userpopyear1):

Year Patients

1 2017 1636560
2 2018 1648388
3 2019 1659951
4 2020 1662533
5 2021 1648324

Simple sample plots and the errors from the console:

userpopyear1 %>%
  ggplot(aes(x = Year, y = Patients)) +
  geom_line()

> userpopyear1 %>%
+   ggplot(aes(x = Year, y = Patients)) +
+   geom_line()
Error in identicalUnits(x) : object is not a unit

userpopyear1 %>%
  ggplot(aes(x = Year, y = Patients)) +
  geom_bar(stat = "identity”)

> userpopyear1 %>%
+   ggplot(aes(x = Year, y = Patients)) +
+   geom_bar(stat = "identity")
Error in identicalUnits(x) : object is not a unit

I have also tried changing the year to a factor but receive the same error message.

My setup:
MacMini with M1 chip
OSX 13.2.1 (Ventura)
R 4.2.3 GUI 1.79 ARM build
RStudio 2023.02.0+386

Again, this may not be related to RStudio, but I can't figure out why I'm getting this error or what I can do to prevent it.
Any information is appreciated!

Libraries I am using:

library(tidyverse)
library(corrplot)
library(lubridate)
library(data.table)
library(caret)
library(factoextra)
library(scales)
library(broom)
library(ComplexUpset)
library(flextable)
library(reactable)
library(ggrepel)
library(mapboxapi)
library(qdrmapbox)
library(sp)
library(leaflet)
library(leaflegend)
library(patchwork)
library(htmltools)
library(plotly)
library(ggplot2)
d <- data.frame(
  Year = 2017:2021, 
  Patients = c(1636560, 1648388, 1659951, 1662533, 1648324))

str(d)
#> 'data.frame':    5 obs. of  2 variables:
#>  $ Year    : int  2017 2018 2019 2020 2021
#>  $ Patients: num  1636560 1648388 1659951 1662533 1648324

d |> 
  ggplot(aes(x = Year, y = Patients)) +
  geom_line()


d |> 
  ggplot(aes(x = Year, y = Patients)) +
  geom_col()


sessionInfo()
#> R version 4.2.2 (2022-10-31)
#> Platform: aarch64-apple-darwin20 (64-bit)
#> Running under: macOS Ventura 13.2.1
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] ggplot2_3.4.1
#> 
#> loaded via a namespace (and not attached):
#>  [1] compiler_4.2.2    pillar_1.9.0      R.methodsS3_1.8.2 R.utils_2.12.2   
#>  [5] tools_4.2.2       digest_0.6.31     evaluate_0.20     lifecycle_1.0.3  
#>  [9] tibble_3.2.1      gtable_0.3.3      R.cache_0.16.0    pkgconfig_2.0.3  
#> [13] rlang_1.1.0       reprex_2.0.2      cli_3.6.0         rstudioapi_0.14  
#> [17] yaml_2.3.7        xfun_0.37         fastmap_1.1.1     withr_2.5.0      
#> [21] styler_1.9.1      dplyr_1.1.1       knitr_1.42        generics_0.1.3   
#> [25] fs_1.6.1          vctrs_0.6.1       grid_4.2.2        tidyselect_1.2.0 
#> [29] glue_1.6.2        R6_2.5.1          fansi_1.0.4       rmarkdown_2.20   
#> [33] farver_2.1.1      purrr_1.0.1       magrittr_2.0.3    scales_1.2.1     
#> [37] htmltools_0.5.5   colorspace_2.1-0  labeling_0.4.2    utf8_1.2.3       
#> [41] munsell_0.5.0     R.oo_1.25.0

Created on 2023-03-23 with reprex v2.0.2

Thank you for the response; however, I am not having a problem with making the code to create the plots, the problem I am having is that as of Wednesday evening, after updating, I am suddenly getting the error "Error in identicalUnits(x) : object is not a unit" when I try to run them. I do not know what this error means or why I'm seeing it.

The error message is consistent - it will always appear, but sometimes I can restart RStudio, work through my script and get the first one or two plots to display once, however, if I try to do it again or if I try to plot more, I will get the error.

I am unable to bypass the error and I can't think of anything to do to prevent the error from occurring. A web search of the error does not show any information - so I'm stuck until I can figure out what may be going on.

I think my lesson learned is to only update the app or one package at a time.

I think I found my solution ...
After going back and turning off various packages one at a time, it appears that the reactablefmtr package is causing the error to occur. When I do not load the reactablefmtr library at the start of an R session, I am not getting the error message.
R is back to working and life is good!

1 Like

Always a good idea to refresh session periodically anyway

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.