Unable publish to R version >= R4.0.0 to old version R packages

Preparing to deploy application...DONE
Uploading bundle for application: 14028...DONE
Deploying bundle: 32805 for application: 14028 ...
[Connect] Building Shiny application...
[Connect] Bundle requested R version 4.0.3; using /opt/R/3.6.2/bin/R which has version 3.6.2
[Connect] 2020/11/24 14:28:24.495671886 Using user agent string: 'RStudio R (3.6.2 x86_64-pc-linux-gnu x86_64 linux-gnu)' 
[Connect] 2020/11/24 14:28:25.723080431 Running on host: beta01
[Connect] 2020/11/24 14:28:25.792230704 linux distribution: Ubuntu 18.04.4 LTS (bionic) 
[Connect] 2020/11/24 14:28:25.793248600 # Validating R library read / write permissions --------------------------------
[Connect] 2020/11/24 14:28:25.793785414 R version: 3.6.2
[Connect] 2020/11/24 14:28:25.807176504 # Validating managed packrat installation --------------------------------------
[Connect] 2020/11/24 14:28:25.807613228 Vendored packrat archive: /opt/rstudio-connect/ext/R/packrat_0.5.0-26_8753d425f363c420846fe05bcba05e5e9b080bb5.tar.gz
[Connect] 2020/11/24 14:28:25.863211248 Vendored packrat SHA: 8753d425f363c420846fe05bcba05e5e9b080bb5
[Connect] 2020/11/24 14:28:25.866450262 Managed packrat SHA:  8753d425f363c420846fe05bcba05e5e9b080bb5
[Connect] 2020/11/24 14:28:25.867758630 Managed packrat version: 0.5.0.26
[Connect] 2020/11/24 14:28:25.868715552 Managed packrat is up-to-date.
[Connect] 2020/11/24 14:28:25.869059148 # Validating packrat cache read / write permissions ----------------------------
[Connect] 2020/11/24 14:28:26.325846433 Audited package hashes with local packrat installation.
[Connect] 2020/11/24 14:28:26.385359505 Package repository URLs are being overridden with the following values:
[Connect] 2020/11/24 14:28:26.385375229 Repository: CRAN = https://demo.rstudiopm.com/all/__linux__/bionic/latest
[Connect] 2020/11/24 14:28:26.385406703 Repository: RSPM = https://demo.rstudiopm.com/all/__linux__/bionic/latest 
[Connect] 2020/11/24 14:28:26.446579837 # Installing required R packages with `packrat::restore()` ---------------------
[Connect] 2020/11/24 14:28:26.749282845 Installing BH (1.72.0-3) ... 
[Connect] 2020/11/24 14:28:26.792683689 Using cached BH.
[Connect] 2020/11/24 14:28:26.793721175 	OK (symlinked cache)
[Connect] 2020/11/24 14:28:26.793894138 Installing DistributionUtils (0.6-0) ... 
[Connect] 2020/11/24 14:28:26.819885627 Using cached DistributionUtils.
[Connect] 2020/11/24 14:28:26.820895216 	OK (symlinked cache)
[Connect] 2020/11/24 14:28:26.821064921 Installing FNN (1.1.3) ... 
[Connect] 2020/11/24 14:28:26.849720103 Using cached FNN.
[Connect] 2020/11/24 14:28:26.850707442 	OK (symlinked cache)
[Connect] 2020/11/24 14:28:26.850881052 Installing KernSmooth (2.23-17) ... 
[Connect] 2020/11/24 14:28:26.881025486 Using cached KernSmooth.
[Connect] 2020/11/24 14:28:26.882157660 	OK (symlinked cache)
[Connect] 2020/11/24 14:28:26.882348990 Installing MASS (7.3-53) ... 
[Connect] 2020/11/24 14:28:26.928491457 Using cached MASS.
[Connect] 2020/11/24 14:28:26.929421031 	OK (symlinked cache)
[Connect] 2020/11/24 14:28:26.929592911 Installing R6 (2.5.0) ... 
[Connect] 2020/11/24 14:28:26.957670158 Using cached R6.
[Connect] 2020/11/24 14:28:26.958602415 	OK (symlinked cache)
[Connect] 2020/11/24 14:28:26.958779554 Installing Rcpp (1.0.5) ... 
[Connect] 2020/11/24 14:28:26.995994523 Using cached Rcpp.
[Connect] 2020/11/24 14:28:26.997087823 	OK (symlinked cache)
[Connect] 2020/11/24 14:28:26.997096267 Installing XML (3.99-0.5) ... 
[Connect] 2020/11/24 14:28:27.203092797 curl: HTTP 200 https://demo.rstudiopm.com/all/__linux__/bionic/latest/src/contrib/PACKAGES.rds
[Connect] 2020/11/24 14:28:52.276032666 curl: HTTP 200 https://rspm-sync.rstudio.com/v3/1/packages/60529b7360f162eba07da455eeb9b94a732b2dd623c49e0f04328a2e97bd53a6.tar.gz
[Connect] 2020/11/24 14:28:53.999885636 Error: Command failed (1)
[Connect] 2020/11/24 14:28:53.999901237 
[Connect] 2020/11/24 14:28:53.999932611 Failed to run system command:
[Connect] 2020/11/24 14:28:53.999933762 
[Connect] 2020/11/24 14:28:53.999941447 	'/opt/R/3.6.2/lib/R/bin/R' --vanilla CMD INSTALL --preclean '/opt/rstudio-connect/mnt/tmp/RtmpxKKkQD/packrat-install-6cd27d5eee90/XML' --library='/opt/rstudio-connect/mnt/app/packrat/lib/x86_64-pc-linux-gnu/3.6.2' --install-tests --no-docs --no-multiarch --no-demo 
[Connect] 2020/11/24 14:28:53.999957891 
[Connect] 2020/11/24 14:28:53.999966066 The command failed with output:
[Connect] 2020/11/24 14:28:53.999967135 ERROR: this R is version 3.6.2, package 'XML' requires R >= 4.0.0
[Connect] 2020/11/24 14:28:54.000041845 
[Connect] 2020/11/24 14:28:54.000046164 Unable to fully restore the R packages associated with this deployment.
[Connect] 2020/11/24 14:28:54.001121901 Please review the preceding messages to determine which package
[Connect] 2020/11/24 14:28:54.001126196 encountered installation difficulty and the cause of the failure.
[Connect] 2020/11/24 14:28:54.036794335 Warning messages:
[Connect] 2020/11/24 14:28:54.036815156 1: In packrat::restore(overwrite.dirty = TRUE, prompt = FALSE, restart = FALSE) :
[Connect] 2020/11/24 14:28:54.036850158   The most recent snapshot was generated using R version 4.0.3
[Connect] 2020/11/24 14:28:54.036851584 2: In getSourceForPkgRecord(pkgRecord, srcDir(project), availablePackagesSource(repos = repos),  :
[Connect] 2020/11/24 14:28:54.036877692   Package version '3.99-0.5' is newer than the latest version reported by CRAN ('3.99-0.3') -- packrat may be unable to retrieve package sources.
[Connect] 2020/11/24 14:28:54.037260840 Error code: r-package-version-not-available

[Connect] A required R package was found in the package repository, but the specified version is not available.

[Connect] Possible causes:
[Connect] * The client computer that published the content is using a different package repository from the Connect server, and the package repository that Connect is using does not have the requested version of the package.
[Connect] * The Connect server is using a CRAN mirror that is out of date.
[Connect] * The package repository moved to a new URL after the content was published, and Connect is now attempting to rebuild the environment using the old package repository URL.
[Connect] 
[Connect] Possible solutions:
[Connect] * Configure the client with a package repository that is accessible via http(s) from the Connect server, such as CRAN or RStudio Package Manager. Reinstall the affected packages from the new repository and publish the content again.
[Connect] * Update the packages on the CRAN mirror.
  - If this is a local instance of RStudio Package Manager, see the Package Manager documentation for instructions on how to update the mirrored packages.
  - If this is a public CRAN mirror, it may be experiencing technical problems. Choose a different CRAN mirror.
[Connect] 
[Connect] References:
[Connect] * https://docs.rstudio.com/rspm/admin/repositories/#sync-schedule
[Connect] * https://docs.rstudio.com/rspm/admin/appendix/airgapped-installs/#air-gapped-updates
[Connect] * https://support.rstudio.com/hc/en-us/articles/360004067074-Managing-Packages-with-RStudio			
[Connect] 
[Connect] 2020/11/24 14:28:54.037260840 Additional data:
[Connect] RepositoryName: 'CRAN'
[Connect] AvailableVersion: '3.99-0.3'
[Connect] Package: 'XML'
[Connect] PackageVersion: '3.99-0.5'
[Connect] Found in the following log entry:
[Connect] 2020/11/24 14:28:54.036877692   Package version '3.99-0.5' is newer than the latest version reported by CRAN ('3.99-0.3') -- packrat may be unable to retrieve package sources.
[Connect] Build error: A required R package was found in the package repository, but the specified version is not available. (r-package-version-not-available)
Application deployment failed with error: A required R package was found in the package repository, but the specified version is not available. (r-package-version-not-available)

Whew! Sorry it's been so long! Are you still encountering this issue? Or did you end up getting it sorted out!?

I'm not sure if he is but I'm having the same exact problem.

Hey @tannerj! Welcome to RStudio Community! And thanks for reaching out here! What "source" of packages are you using? CRAN? An internal CRAN? RStudio Package Manager?

In the latter cases, things get more tricky, but depending on the root cause of the problem, often this can be resolved by:

(1) Adding a newer / different version of R to the RStudio Connect server
(2) Installing a different version of the package locally in your dev environment (i.e. a version that does not require R >= 4.0.0) and then republishing
(3) ensuring that the source of your packages (i.e. Internal CRAN) is up to date