-
Notifications
You must be signed in to change notification settings - Fork 0
/
quickstart.rmd
78 lines (56 loc) · 1.76 KB
/
quickstart.rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
---
title: "Quickstart to arcpy"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Quickstart}
%\VignetteEngine{knitr::rmarkdown}
\usepackage[utf8]{inputenc}
---
Getting started with `{arcpy}` in R is easy. If you're using ArcGIS Pro,
you'll first need to create a Conda environment that will link to your
ArcGIS Pro install. If you're not familiar with Conda or the
[`reticulate`](https://cran.r-project.org/package=reticulate)
package, check the vignettes
[Calling Python from R](https://rstudio.github.io/reticulate/articles/calling_python.html) and
[Python Version Configuration](https://rstudio.github.io/reticulate/articles/versions.html).
For example, here's how you would create a Conda
environment to link to an ArcGIS Pro 3.1 install.
```r
library(arcpy)
install_arcpy(version = "3.1")
```
If you don't specify the python version, the package will use the
latest compatible Python version based on what is reported in the
arcpy module build. By default, the package creates a new environment
named "r-arcpy", but this can be overridden.
`{arcpy}` automatically provides a `reticulate` module object
called `arcpy`. This object provides the interface to ArcGIS.
```r
arcpy
```
```
## Module(arcpy)
```
```r
arcpy$GetInstallInfo()$ProductName
```
```
## [1] "ArcGISPro"
```
Once you are connected to your ArcGIS installation, using `arcpy` functions
and classes is as seamless as using any other Python module via `reticulate`.
```r
# get and set the arcpy environment
arcpy$env$workspace = tempdir()
arcpy$env$workspace
```
```
## [1] "C:\\Temp\\1\\RtmpGWDuu8"
```
`{arcpy}` also re-exports reticulate's `py_help` function so that
you can access the `arcpy` documentation.
```r
# get help on arcpy functions
py_help(arcpy$Exists)
```
Happy scripting!