Title: How to interpret and fix 'shared object not found' error when importing library in R on MacOS in a conda environment?
Tags: python,r,macos,conda,rpy2

Question: I am attempting to import an R package from a specific R path in a conda environment, but I keep receiving the following error:
Error: package or namespace load failed for ‘marginaleffects’ in library.dynam(lib, package, package.lib):
shared object ‘data_table.so’ not found

I am struggling to understand not just how to fix this error, but also what this error means or where it is coming from.
Specifically, I am deploying a web application with the Python-based streamlit framework and am using the package rpy2 to interface from an existing R codebase to Python. I use conda/mamba as the package manager on my machine. I have installed all R packages using their conda-forge distribution as possible. There are several R packages that are not available, so I have installed them in R to the path of my desired library with with: install.packages("marginaleffects", dep = TRUE, lib = "/Users/myuser/mambaforge/envs/myenv/lib/R/library", verbose = TRUE). The package then appears to exist in the directory .../myenv/lib/R/library, in installed.packages(), and in RStudio's list of packages.
However, when I attempt to load the package with library(marginaleffects, lib.loc="/Users/myuser/mambaforge/envs/myenv/lib/R/library") I receive the error noted above. Note that if I import this Packages in an R code run in the streamlit app, it raises a slightly different error relating to a .dylib shared object, instead of an '.so` shared object.
RRuntimeError: Error: package or namespace load failed for ‘marginaleffects’ in library.dynam(lib, package, package.lib): shared object ‘marginaleffects.dylib’ not found

I have the vaguest sense this has something to do with a compiler error. I have also been unsuccessful in installing the package through the rpy2 framework, receiving a long and fairly inscrutable error message.
EDIT
The code I have run so far for reproducibility on a MacOS (Ventura, same issue happened on Big Sur):
zsh> mamba create -n myenv r-essentials r-base python=3.8
zsh> mamba activate myenv
zsh> mamba install -c r rpy2 
zsh> mamba install -c conda-forge pandas
zsh> mamba install -c conda-forge streamlit

R> install.packages("clarify", dep = TRUE, lib = "/Users/myname/mambaforge/envs/myenv/lib/R/library", verbose = TRUE)
R> install.packages("marginaleffects", dep = TRUE, lib = "/Users/myname/mambaforge/envs/myenv/lib/R/library", verbose = TRUE)
R> library(marginaleffects, lib.loc="/Users/myuser/mambaforge/envs/myenv/lib/R/library")

Error: package or namespace load failed for ‘marginaleffects’ in library.dynam(lib, package, package.lib):
shared object ‘data_table.so’ not found

EDIT2
I am running osx-64.

Answer: In addition to @merv's answer above, which I have accepted, I was able to resolve this issue with a slightly different approach by doing two things. This may be helpful for anyone troubleshooting a similar problem.

Sequencing: Installing streamlit last and using pip instead of conda. Once I had installed all the other required packages, I could not get conda to find a compatible distribution of streamlit. Installing with pip seems to work fine, however.
Consistency in installation: Installing all R packages through conda (technically mamba) instead of  install.packages in R. (Thanks again to @merv for rapidly getting r-clarify up.)