Skip to content

Commit c86f7b3

Browse files
committed
updates to R
package management topics
1 parent c47806b commit c86f7b3

7 files changed

Lines changed: 290 additions & 349 deletions

docs/advanced-analytics/r/create-a-local-package-repository-using-minicran.md

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Create a local package repository using miniCRAN | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "09/29/2017"
4+
ms.date: "01/04/2018"
55
ms.reviewer:
66
ms.suite: sql
77
ms.prod: machine-learning-services
@@ -30,7 +30,12 @@ There are two ways that you can prepare R packages for installation onto a serve
3030

3131
- [Manually download and copy packages one by one](#bkmk_manual)
3232

33-
This article describes how you can create an R package repository using both methods, and recommends use of the **miniCRAN** package.
33+
You can find the list of dependent packages in the DESCRIPTION file for the downloaded package.
34+
35+
However, packages listed in **Imports** might have second-level dependencies. For this reason, we recommend use of the **miniCRAN** method.
36+
37+
> [!TIP]
38+
> Did you know that you can use miniCRAN to prepare packages for use in Azure Machine Learning? For more information, see this blog: [Using miniCRAN in Azure ML, by Michele Usuelli](https://www.r-bloggers.com/using-minicran-in-azure-ml/)
3439
3540
## Prepare packages using miniCRAN
3641

@@ -48,6 +53,9 @@ There are many advantages to using miniCRAN to create the repository:
4853

4954
After creating the repository, you can modify it by adding new packages or upgrading the version of existing packages.
5055

56+
> [!NOTE]
57+
> The miniCRAN package itself is dependent on 18 other CRAN packages, among which is the RCurl package, which has a system dependency on the curl-devel package. Similarly, package XML has a dependency on libxml2-devel. We recommend, therefore, that you build your local repository initially on a machine with full Internet access, so that you can easily satisfy all these dependencies. After created, you can move the repository to a different location.
58+
5159
### Step 1. Install the miniCRAN package
5260

5361
You begin by creating a miniCRAN repository to use as a source. You should create this repository on a computer that has internet access.
@@ -67,9 +75,11 @@ You begin by creating a miniCRAN repository to use as a source. You should creat
6775
CRAN_mirror \<- c(CRAN = "https://mran.microsoft.com/snapshot/2017-08-01")
6876
```
6977

70-
2. Indicate a local folder in which to store the collected packages. You needn't name the folder miniCRAN; it could be a more descriptive name like "GeneticsPackages" or "ClientRPackages1.0.2".
78+
2. Type the name of a local folder in which to store the collected packages.
7179

72-
Just be sure to create the folder in advance. An error is raised if the `local_repo` folder does not exist when you run the R code later.
80+
Be sure to create the folder in advance. An error is raised if the `local_repo` folder does not exist when you run the R code later.
81+
82+
The folder should have a desriptive name; that is, not "miniCRAN", but something like "GeneticsPackages" or "TeamRPackages1.0.2".
7383

7484
```R
7585
local_repo <- "~/miniCRAN"
@@ -81,7 +91,7 @@ You begin by creating a miniCRAN repository to use as a source. You should creat
8191

8292
1. After miniCRAN is installed, create a list that specifies the additional packages you want to download.
8393

84-
Do not add dependencies to this initial list; the **igraph** package used by miniCRAN generates the list of dependencies for you. For more information about how to use this graph, see [Using miniCRAN to identify package
94+
Do not add dependencies to this initial list; the **igraph** package used by miniCRAN generates the list of dependencies for you. For more information about how to use the generated dependency graph, see [Using miniCRAN to identify package
8595
dependencies](https://cran.r-project.org/web/packages/miniCRAN/vignettes/miniCRAN-dependency-graph.html).
8696

8797
The following R script demonstrates how to get the target packages, "zoo"
@@ -90,7 +100,7 @@ You begin by creating a miniCRAN repository to use as a source. You should creat
90100
```R
91101
pkgs_needed <- c("zoo", "forecast")
92102
```
93-
2. Optionally, plot the dependency graph, which can be informative and looks cool.
103+
2. It is not required that you plot the dependency graph, but it can be informative.
94104

95105
```R
96106
plot(makeDepGraph(pkgs_needed))
@@ -122,15 +132,15 @@ After you have created the repository and added the packages you need, you must
122132

123133
Depending on the version of SQL Server, there are two options for adding new packages to the R library associated with the SQL Server instance:
124134

125-
- Install to the instance library using the miniCRAN repository and R tools.
135+
- Install to the instance library using the miniCRAN repository and R tools.
126136

127-
- Upload packages to a SQL database and install packages on a per-database basis, using the CREATE EXTERNAL LIBRARY statement. See [Install additional R packages on SQL Server](install-additional-r-packages-on-sql-server.md).
137+
- Upload packages to a SQL Server database and install using the CREATE EXTERNAL LIBRARY statement. This ption requires SQL Server 2017. See [Install additional R packages on SQL Server](install-additional-r-packages-on-sql-server.md).
128138

129139
The following procedure describes how to install the packages using R tools.
130140

131-
1. Copy the folder containing the miniCRAN repository, in its entirety, to the server where you will install the packages.
141+
1. Copy the folder containing the miniCRAN repository, in its entirety, to the server where you will install the packages.
132142

133-
2. Open an R command prompt using the R tool associated with the instance.
143+
2. Open an R command prompt using the R tool associated with the instance.
134144

135145
- For SQL Server 2017, the default folder is `C:/Program Files/Microsoft SQL Server/MSSQL14.MSSQLSERVER/R_SERVICES/library`.
136146

@@ -140,58 +150,55 @@ The following procedure describes how to install the packages using R tools.
140150

141151
- If you have installed SQL Server to a different drive, or made any other changes in the installation path, be sure to make those changes as well.
142152

143-
3. Get the path for the instance library (in case you're in a user directory), and add it to the list of library paths.
153+
3. Get the path for the instance library, and add it to the list of library paths.
144154

145155
```R
146156
.libPaths()[1]
147157
lib \<- .libPaths()[1]
148158
```
149159

150-
This should return the instance path, "C:/Program Files/Microsoft SQL Server/MSSQL14.MSSQLSERVER/R_SERVICES/library "
160+
On SQL Server, this command should return the path of the library associated with the instance, such as: "C:/Program Files/Microsoft SQL Server/MSSQL14.MSSQLSERVER/R_SERVICES/library "
151161

152-
2. Specify the location on the server where you copied the mininCRAN repository in `server_repo`.
162+
4. Specify the location on the server where you copied the mininCRAN repository in `server_repo`.
153163

154164
In this example, we assume that you copied the repository to your user folder on the server.
155165

156166
```R
157167
R server_repo <- "C:\\Users\\MyUserName\\miniCRAN"
158168
```
159169

160-
3. Since you are working in a new R workspace on the server, you must also furnish the list of packages to install.
170+
5. Since you are working in a new R workspace on the server, you must also furnish the list of packages to install.
161171

162172
```R
163173
tspackages <- c("zoo", "forecast")
164174
```
165175

166-
4. Install the packages, using the path to the local copy of the miniCRAN repo.
176+
6. Install the packages, providing the path to the local copy of the miniCRAN repo.
167177

168178
```R
169179
install.packages(tspackages, repos = file.path("file://", normalizePath(server_repo, winslash = "/")), lib = lib, type = "win.binary", dependencies = TRUE)
170180
```
171181

172-
5. Now view the installed packages.
182+
7. From the instance library, you can view the installed packages using a command like the following:
173183

174184
```R
175185
installed.packages()
176186
```
177187

178188
> [!NOTE]
179-
>
180-
> In SQL Server 2017, additional database roles and T-SQL statements are provided to help server administrators manage permissions over packages. The database administrator can own the task of installing packages, using either R or T-SQL, if so desired. However, the DBA can also use roles to give users the ability to install their own packages. For more information, see [R package management for SQL Server](r-package-management-for-sql-server-r-services.md).
181-
>
182-
> In SQL Server 2016, a server administrator must install packages from the miniCRAN repository into the default library used by the instance. To do this, use the R tools as described in the [preceding section](#bkmk_Rtools).
189+
> In SQL Server, a server administrator must install packages from the miniCRAN repository into the default library used by the instance.
183190

184191
## Manually download single packages
185192

186193
If you do not want to use miniCRAN, you can also manually download the packages you need, and their dependencies. To do this requires that you are either an administrator or sole owner of a server.
187194

188195
After downloading the packages, you install the R packages from the zipped file location.
189196

190-
1. Download the packages zip files, and save them in a local folder
197+
1. Download the packages zip files, and save them in a local folder
191198

192-
2. Copy that folder to the [!INCLUDE[ssNoVersion_md](..\..\includes\ssnoversion-md.md)] computer.
199+
2. Copy that folder to the [!INCLUDE[ssNoVersion_md](..\..\includes\ssnoversion-md.md)] computer.
193200

194-
3. Install the packages into the SQL Server instance library.
201+
3. Install the packages into the SQL Server instance library.
195202

196203
> [!NOTE]
197204
> When you use R tools to install packages, they are installed for the instance as a whole.

docs/advanced-analytics/r/determine-which-packages-are-installed-on-sql-server.md

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Determine which R packages are installed on SQL Server | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "10/09/2016"
4+
ms.date: "01/04/2018"
55
ms.reviewer:
66
ms.suite: sql
77
ms.prod: machine-learning-services
@@ -20,7 +20,7 @@ ms.workload: "Inactive"
2020
---
2121
# Determine which R packages are installed on SQL Server
2222

23-
When you install machine learning in SQL Server with the R language option, setup creates an R package library associated with the instance. Each instance has a separate package library. Package libraries are **not** shared across instances, so it is possible for different packages to be installed on different instances.
23+
When you install machine learning in SQL Server with the R language option, an R package library is created and associated with the instance. Each instance has its own package library. Package libraries cannot be shared across instances.
2424

2525
This article describes how you can determine which R packages are installed for a specific instance.
2626

@@ -30,37 +30,35 @@ The following example uses the R function `installed.packages()` in a [!INCLUDE[
3030

3131
```SQL
3232
EXECUTE sp_execute_external_script
33-
@language=N'R'
34-
,@script = N'str(OutputDataSet);
35-
packagematrix <- installed.packages();
36-
NameOnly <- packagematrix[,1];
37-
OutputDataSet <- as.data.frame(NameOnly);'
38-
,@input_data_1 = N'SELECT 1 as col'
39-
WITH RESULT SETS ((PackageName nvarchar(250) ))
33+
@language=N'R'
34+
,@script = N'str(OutputDataSet);
35+
packagematrix <- installed.packages();
36+
NameOnly <- packagematrix[,1];
37+
OutputDataSet <- as.data.frame(NameOnly);'
38+
, @input_data_1 = N''
39+
WITH RESULT SETS ((PackageName nvarchar(250) ))
4040
```
4141

42-
For more information about the optional and default fields for the R package DESCRIPTION file, see
42+
For more information about the optional and default fields for the R package DESCRIPTION field, see
4343
[https://cran.r-project.org](https://cran.r-project.org/doc/manuals/R-exts.html#The-DESCRIPTION-file).
4444

4545
## Verify whether a package is installed with an instance
4646

47-
If you have installed a package and want to make sure that it is available to a particular SQL Server instance, you can execute the following stored procedure call to load the package and return only messages.
47+
If you have installed a package and want to make sure that it is available to a particular SQL Server instance, you can execute the following stored procedure call to load the package and return only messages. This example looks for and loads the RevoScaleR library, if available.
4848

4949
```SQL
5050
EXEC sp_execute_external_script @language =N'R',
5151
@script=N'library("RevoScaleR")'
5252
GO
5353
```
5454

55-
This example looks for and loads the RevoScaleR library.
55+
+ If the package is found, a message is returned: "Commands completed successfully."
5656

57-
+ If the package is found, the message returned should be something like "Commands completed successfully."
58-
59-
+ If the package cannot be located or loaded, you get an error like this: "An external script error occurred: Error in library("RevoScaleR"): there is no package called RevoScaleR"
57+
+ If the package cannot be located or loaded, you get an error containing the text: "there is no package called 'MissingPackageName'"
6058

6159
## Get a list of installed packages using R
6260

63-
There are multiple ways to get a list of installed or loaded packages using R tools and R functions. Many R development tools provide an object browser or a list of packages that are installed or that are loaded in the current R workspace.
61+
There are multiple ways to get a list of installed or loaded packages using R tools and R functions. Many R development tools provide an object browser or a list of packages that are installed or that are loaded in the current R workspace. This section provides some short commands that you can use from any R command line or in sp\_execute\_external\_script.
6462

6563
+ From a local R utility, use a base R function, such as `installed.packages()`, which is included in the `utils` package. To get a list that is accurate for an instance, you must either specify the library path explicitly, or use the R tools associated with the instance library.
6664

@@ -77,6 +75,16 @@ sqlServerCompute <- RxInSqlServer(connectionString = "Driver=SQL Server;Server=m
7775
sqlPackages <- rxInstalledPackages(computeContext = sqlServerCompute)
7876
sqlPackages
7977
```
78+
79+
## Get library location and version
80+
81+
The following example gets the library location of RevoScaleR in the local compute context, and the package version.
82+
83+
```r
84+
rxFindPackage(RevoScaleR, "local")
85+
packageVersion("RevoScaleR")
86+
```
87+
8088
## See also
8189

8290
[Install additional R packages on SQL Server](install-additional-r-packages-on-sql-server.md)

0 commit comments

Comments
 (0)