Internal Package Publishing


Sometimes you'll want to deploy an app with a set of internal packages not publicly available. To do this, there are some special instructions that should be adhered to.

In this scenario, we'll assume you have the following internal packages: internal_one, internal_two associated with your app.

You'll want to build and compress your package into a gzipped tarball to be transfered to your RStudio Connect instance. To do this, simply run devtools::build() from the root directory of the internal package.

Place the files in the root directory of your app:

Package tarball

Then you'll need to create a packrat folder in your root directory. This will tell RStudio Connect which packages to ignore installing by default. Inside the packrat directory, create a single text file called packrat.opts with the following text:

auto.snapshot: FALSE
use.cache: FALSE
print.banner.on.startup: auto
vcs.ignore.lib: TRUE
vcs.ignore.src: FALSE
external.packages: 
local.repos: 
load.external.packages.on.startup: TRUE
ignored.packages: 
	internal_one
	internal_two
ignored.directories:
    data
    inst
quiet.package.installation: TRUE
snapshot.recommended.packages: FALSE
snapshot.fields:
    Imports
    Depends
    LinkingTo
symlink.system.packages: TRUE

Make sure to replace internal_one, internal_two with your specific internal packages.

Now you'll need to install your package once it's deployed. Include the following code (ideally at the top of your global.R or app.R file):

if(!requireNamespace("internal_one", quietly = TRUE)){
  install.packages(
    "internal_one_0.2.0.tar.gz",
    repos = NULL, 
    type="source"
  )
}

if(!requireNamespace("internal_two", quietly = TRUE)){
  install.packages(
    "internal_two_1.0.0.tar.gz",
    repos = NULL, 
    type="source"
  )
}

This will ensure that the associated packages are installed when the app is run.

Finally you'll need to run the following command to deploy this app:

rsconnect::deployApp(

  appName = "TestApp", 
  appDir = "TestApp",
  contentCategory = "site",
  
  appFiles = c("server.R",
               "ui.R", 
               "internal_one_0.2.0.tar.gz",
               "internal_two_1.0.0.tar.gz",
               "packrat/packrat.opts")
)

Make sure to replace the variables with the appropriate values! That's it!