title: Temporarily ignore certain libraries in R
body: <p>I am currently working on a continuous integration setup for R packages developed by our company. We have one Jenkins project for each R package and a corresponding library for each project.</p>
  
  <p>I already defined a logic that installs all dependencies of the package into the project library. Now i want to define a check stage which basically runs</p>
  
  <pre><code>devtools::check("${PROJECT_DIR}/pkg")
  </code></pre>
  
  <p>but <em>only use the project library</em> for dependencies. I tried to use the <code>callr</code> package in the following manner.</p>
  
  <pre><code>callr::r(
    function(...) {
      devtools::check(...)
    ),
    args = list("${PROJECT_DIR}/pkg"),
    libpath = "${PROJECT_DIR}/lib"
  )
  </code></pre>
  
  <p>However, the check process is still able to find packages which are not installed in <code>libpath</code>. Is there a way to make sure that only <code>"${PROJECT_DIR}/lib"</code> is used during the build stage?</p>
  
  <p>So far, I have tried the following to no avail</p>
  
  <ul>
  <li><code>callr()</code> with the <code>libpath</code> argument</li>
  <li><code>withr::with_libpaths</code> with the <code>new</code> argument</li>
  <li>Look through the documentation in <code>devtools::check</code> and <code>R CMD BUILD</code> for 
  appropriate parameters</li>
  <li>Use <code>.libPaths("${JOB_DIR}/lib")</code></li>
  </ul>
  
  <hr>
  
  <p>Here is a repex to explain the unexpected behavior of <code>callr</code>. I expect an error in line 3.</p>
  
  <pre class="lang-r prettyprint-override"><code>find.package("ggplot2", .libPaths()[1])
  #&gt; Error in find.package("ggplot2", .libPaths()[1]): there is no package called 'ggplot2'
  callr::r(function() {  ggplot2::vars() }, libpath = .libPaths()[1])
  #&gt; named list()
  find.package("ggplot2", .libPaths()[2])
  #&gt; [1] "/data/R/3.5.3/lib/R/library/ggplot2"
  callr::r(function() {  ggplot2::vars() }, libpath = .libPaths()[2])
  #&gt; named list()
  </code></pre>