-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
157 lines (106 loc) · 3.96 KB
/
README.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
---
output: github_document
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%",
eval = megamation:::has_creds()
)
```
```{r eval = !megamation:::has_creds(), echo = FALSE, comment = NA}
message("Missing credentials. Code chunks will not be evaluated.")
```
```{r, include = FALSE}
library(httptest2)
start_vignette("README")
```
# megamation <a href="https://asadow.github.io/megamation/"><img src="man/figures/logo.png" alt="megamation website" align="right" height="139"/></a>
**Authors:**
[Adam Sadowski](https://adams.quarto.pub/w/)<br/>
**License:**
[GPL (>= 3)](https://www.gnu.org/licenses/licenses.html)
<!-- badges: start -->
[![R-CMD-check](https://github.com/asadow/megamation/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/asadow/megamation/actions/workflows/R-CMD-check.yaml) [![Codecov test coverage](https://codecov.io/gh/asadow/megamation/branch/master/graph/badge.svg)](https://app.codecov.io/gh/asadow/megamation?branch=master) [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
<!-- badges: end -->
## Overview
megamation provides an R interface to [Megamation DirectLine](https://megamation.com/) via the [API](https://apidocs.megamation.com/).
## Installation
You can install the released version of megamation from [CRAN](https://cran.r-project.org/) with:
```{r, eval = FALSE}
install.packages("megamation")
```
And the development version from [GitHub](https://github.com/) with:
```{r, eval = FALSE}
# install.packages("pak")
pak::pak("asadow/megamation")
```
## Attach megamation
```{r}
library(megamation)
```
## Authorization
You have two options.
Either use `mm_authorize()`:
```{r, eval = FALSE}
mm_authorize(
key = "<YOUR-MEGAMATION_KEY>",
url = "<YOUR-MEGAMATION_URL>"
)
```
Or run `usethis::edit_r_environ()` to install your API credentials in your `.Renviron`.
``` {r, eval = FALSE}
MEGAMATION_KEY = '<YOUR-MEGAMATION_KEY>'
MEGAMATION_URL = '<YOUR-MEGAMATION_URL>'
```
Now `megamation` functions will automatically use your credentials, so you don't
have to expose them in your code.
## Grabbing Data
`mm_data()` downloads data from your tables into R.
```{r}
mm_data("status")
```
It provides informative R errors (alongside HTTP errors).
```{r, error = TRUE}
mm_data("statuses")
```
### Filtering
`mm_data()` allows you to easily filter by fields (columns).
#### Available Filters
`mm_names()` allows you to see the columns that can act as filters.
```{r}
mm_names("workorder")
```
#### Modifiers
You can use Megamation's [modifiers](https://apidocs.megamation.com/) on filter values.
- `[]` for containing
- `!!` for not equal
- `>>` for greater than
- `<<` for less than
- `<>` for between.
For example, supply `<field> = "[]<value>"` to get rows where `<field>` contains `<value>`. Here's how you would request all work orders containing trades `ADMIN` and `IT`.
```{r, eval = FALSE}
admin_and_it <- c("[]ADMIN", "[]IT")
mm_data("workorder", trade = admin_and_it)
#> # Data Not Shown for Privacy
```
#### Dates
Avoid `<>` for dates. Instead, use a sequence of R `Date`'s. Here's how you would request all work orders from January, 2023.
```{r, eval = FALSE}
jan_2023 <- seq.Date(
as.Date("2023-01-01"),
as.Date("2023-01-31"),
by = "day"
)
mm_data("workorder", date = jan_2023)
#> # Data Not Shown for Privacy
```
## For More
Please see the package website: <https://asadow.github.io/megamation/>.
```{r, include = FALSE}
end_vignette()
```
## Code of Conduct
Please note that the megamation project is released with a [Contributor Code of Conduct](https://asadow.github.io/megamation/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms. Feedback, bug reports (and fixes!), and feature requests are welcome; file issues or seek support [here](https://github.com/asadow/megamation/issues).