7.2 Lab
Overview#
In the following exercises, you will:
- Configure RStudio Workbench to point to RSPM for a single user
- Install a package from a repository in RSPM
- Configure RStudio Workbench to point to RSPM globally for all users
- Publish a project to RStudio Connect that fetches packages from RSPM
Refer to the RSPM Documentation throughout the exercises, specifically the Configuring RStudio Server section.
Task: View CRAN repository setting#
- Run the following in a Console in RStudio Workbench:
getOption("repos")
You should see output similar to the following:
CRAN
"https://cran.rstudio.com/"
attr(,"RStudio")
[1] TRUE
- In RStudio Workbench, go to
Tools
>Global Options
>Packages
and view thePrimary CRAN repository
that is currently set.
Task: Configure packages for one user#
As an end user, you can configure the RStudio IDE or RStudio Workbench to point to one or more repositories in RSPM.
In this exercise, you will configure projects for one user on your instance of RStudio Workbench to point to the CRAN repository in your RSPM instance.
-
Navigate to the web interface for your RSPM instance.
-
Choose the CRAN repository called
prod-cran
, then click on theSetup
tab in the top navigation bar, which will provide instructions forUsing Packages Inside RStudio
.
-
Copy the
Repository URL
, which will appear similar tohttp://{IP-ADDRESS}/{REPO-NAME}/latest
-
In RStudio Workbench, go to
Tools
>Global Options
>Packages
. -
Click on the
Change
button in thePrimary CRAN repository
setting. -
In the
Choose Primary Repository
dialog, paste the repository URL into theCustom
field and click theOK
button.
Note
You can also click on the Add
button in the Packages
settings to include a repository as a secondary repository instead of the primary repository.
Task: Install a new package from RSPM#
You can install a new package in RStudio and verify that the new package is being downloaded from the repository in RSPM.
- In RStudio Workbench, use the console to install a new package:
install.packages("abind")
- In the console logs, verify that the package is being downloaded from the desired repository in RSPM.
trying URL 'http://18.188.222.24:4242/prod-cran/latest/src/contrib/abind_1.4-5.tar.gz'
Content type 'application/x-gzip' length 21904 bytes (21 KB)
==================================================
downloaded 21 KB
- In the RSPM web interface, navigate to the
prod-cran
repository that you installed the package from, click on thePackages
link in the top navigation bar, open the details page for theabind
package, and verify that theMonthly Downloads
count is greater than one.
Task: Configure packages for all users#
As an administrator, you can configure all users and projects to point to one or more repositories in RSPM.
In this exercise, you will configure all users and projects on your instance of RStudio Workbench to point to the CRAN repository in your RSPM instance.
-
Open the RStudio Workbench configuration file
/etc/rstudio/rsession.conf
in a text editor. -
Add a line similar to the following to the RStudio Workbench configuration file, replacing
{RSTUDIO-PM-REPO-URL}
with the repository URL for theprod-cran
repository in RSPM:
r-cran-repos={RSTUDIO-PM-REPO-URL}
- Save the RStudio Workbench configuration file, and restart RStudio Workbench using the following command:
sudo rstudio-server restart
Now, all users and projects will fetch packages from the repository in RSPM that you've specified.
The documentation for Configuring RStudio Server provides more details and describes additional scenarios for configuring RStudio Workbench to point to repositories in RSPM.
Task: Publish to RStudio Connect#
Now that you've configured RStudio Workbench to point to a repository in RSPM, projects that are published to RStudio Connect will fetch packages from RSPM.
- Open a project (or create a new project) in RStudio Workbench
- Publish the project to RStudio Connect
How can you confirm that the packages are being served from RStudio Package Manager?
- View the logs in RStudio Connect for the published asset
- View the
Monthly Downloads
count for a package that is used in your project - View the usage statistics in RStudio Package Manager
Bonus Task: Next steps with app_02#
Previously you tried to deploy app_02
from the course material to RStudio Connect. This failed since the rstudiointernal
package was not available. Now you have the tools in place to build a proper solution.
-
Follow the documented steps for Distributing Local Packages to add a new repository that is subscribed to a local source package for
rstudiointernal
: -
Create a local source
- Add local package tar file to source
- Create a repository
-
Subscribe the repository to the source
-
Get the URL for the new repository from the web interface of RStudio Package Manager.
-
Add the new repository as an additional one in RStudio Workbench under
Tools
>Global Options
>Packages
. -
Try to publish
app_02
from before. -
In case of error, you can re-install the
rstudioninternal
package from the new repository using
install.packages("rstudiointernal")
Note that the app still does not work on RStudio Connect? Can you identify the issue?
As an alternative, you could also create a repository based on both CRAN and local source packages following the documented steps for Distributing Local Packages along with CRAN Packages. In that case you would have switched the main repository in RStudio Workbench instead of adding an additional one.
Congratulations on completing the RSPM section of this training course!