title: Is there a way to automate reinstalling packages and their dependencies in r?
body: <p>So I used installR on Rstudio to update R to version 4.0.0, and it copied the files of my packages into the library file in the R, the directory being: <code>C:\Users\Ibrahim\Documents\R\R-4.0.0\library</code></p>
  <p>Whenever I'd call on a package, for example tidytext, it would give me:</p>
  <pre><code>library(tidytext)
  Error: package or namespace load failed for ‘tidytext’:
   package ‘tidytext’ was installed before R 4.0.0: please re-install it 
  </code></pre>
  <p>And then I'd try installing it, and it would give me:</p>
  <pre><code>install.packages('tidytext')
  WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:
  
  https://cran.rstudio.com/bin/windows/Rtools/
  trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.0/tidytext_0.2.4.zip'
  Content type 'application/zip' length 3008780 bytes (2.9 MB)
  downloaded 2.9 MB
  
  package ‘tidytext’ successfully unpacked and MD5 sums checked
  
  The downloaded binary packages are in
      C:\Users\Ibrahim\AppData\Local\Temp\Rtmpmo5Lza\downloaded_packages
  </code></pre>
  <p>Calling it again gives:</p>
  <pre><code>library(tidytext)
  Error: package or namespace load failed for ‘tidytext’:
   package ‘tokenizers’ was installed before R 4.0.0: please re-install it
  </code></pre>
  <p>And I would keep installing the next dependency and recalling the package until it would finally work.</p>
  <p>I tried to automate this with this code I found:</p>
  <pre><code>lib_loc &lt;- &quot;C:/Users/Ibrahim/Documents/R/R-4.0.0/library&quot;
  to_install &lt;- unname(installed.packages(lib.loc = lib_loc)[, &quot;Package&quot;])
  to_install
  install.packages(pkgs = to_install)
  install.packages(pkgs = to_install, dependencies=T, INSTALL_opts='--no-lock')
  </code></pre>
  <p>And that would create a bunch of .zip files to the directory: <code>C:\Users\Ibrahim\AppData\Local\Temp\Rtmpmo5Lza\downloaded_packages</code></p>
  <p>But after a while, it eventually locks, creating a folder/file called 00LOCK in the initial /library directory, and stop the process.</p>
  <p>And I would then delete it, but when I'd run the code again, I guess maybe it redoes many of the files already done, and still eventually locks again. Am I doing anything wrong? Is there a way I can fix this? It's a real pain to do it manually. Should I just reinstall RStudio?</p>