This is because you use renv, and renv installs packages in a different location than what setup-r-dependencies uses. There is a setup-renv action for renv projects, I assume that will save the right directories in the cache, so you might want to try that instead of setup-r-dependencies.
Thanks @Gabor! But I still get an error with setup-renv, but only if I am using the rstanarm package. Here is a simple package which illustrates the behavior:
...
Moving threejs [0.3.3] into the cache ...
OK [moved to cache in 17 milliseconds]
Installing shinystan [2.6.0] ...
OK [installed binary in 0.37 seconds]
Moving shinystan [2.6.0] into the cache ...
OK [moved to cache in 19 milliseconds]
Installing rstanarm [2.21.3] ...
FAILED
Error installing package 'rstanarm':
====================================
* installing *source* package ‘rstanarm’ ...
** package ‘rstanarm’ successfully unpacked and MD5 sums checked
** using staged installation
Error: Error in loadNamespace(x) : there is no package called ‘roxygen2’
Calls: loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
Execution halted
** libs
"/opt/R/4.2.2/lib/R/bin/Rscript" -e "source(file.path('..', 'tools', 'make_cc.R')); make_cc(commandArgs(TRUE))" stan_files/bernoulli.stan
Wrote C++ file "stan_files/bernoulli.cc"
g++ -std=gnu++14 -I"/opt/R/4.2.2/lib/R/include" -DNDEBUG -I"../inst/include" -I"/home/runner/work/testing/testing/renv/staging/1/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -I'/home/runner/work/testing/testing/renv/staging/1/StanHeaders/include' -I'/home/runner/work/testing/testing/renv/staging/1/rstan/include' -I'/home/runner/work/testing/testing/renv/staging/1/BH/include' -I'/home/runner/work/testing/testing/renv/staging/1/Rcpp/include' -I'/home/runner/work/testing/testing/renv/staging/1/RcppEigen/include' -I'/home/runner/work/testing/testing/renv/staging/1/RcppParallel/include' -I/usr/local/include `"/opt/R/4.2.2/lib/R/bin/Rscript" -e "RcppParallel::CxxFlags()"` `"/opt/R/4.2.2/lib/R/bin/Rscript" -e "StanHeaders:::CxxFlags()"` -fpic -g -O2 -c stan_files/bernoulli.cc -o stan_files/bernoulli.o
In file included from /home/runner/work/testing/testing/renv/staging/1/RcppEigen/include/Eigen/Core:397,
from /home/runner/work/testing/testing/renv/staging/1/RcppEigen/include/Eigen/Dense:1,
from /home/runner/work/testing/testing/renv/staging/1/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13,
from /home/runner/work/testing/testing/renv/staging/1/rstan/include/rstan/rstaninc.hpp:3,
from stan_files/bernoulli.hpp:18,
from stan_files/bernoulli.cc:3:
/home/runner/work/testing/testing/renv/staging/1/RcppEigen/include/Eigen/src/Core/arch/SSE/PacketMath.h:60:39: warning: ignoring attributes on template argument ‘__m128’ [-Wignored-attributes]
60 | template<> struct is_arithmetic<__m128> { enum { value = true }; };
...
Thanks @Gabor . Alas, that did not solve the problem. Since title of this thread no longer describe the problem that I am having, I will move this discussion to a new post.