-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
117 lines (86 loc) · 4.05 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
---
output: rmarkdown::github_document
---
`algorithmia` : R interface to the [Algorithmia](https://algorithmia.com/) API
The following functions are implemented:
- `algo_api_key`: Get or set ALGORITHMIA_API_KEY value
- `algo_call`: Call an Algorithmia algorithm
- `algo_client`: Initialize a new Algorithmia API client call
- `algo_dir_exists`: Test if a directory exists
- `algo_dir_list`: List a directory accessible by the Algorithmia service
- `algo_download_file`: Read a file from a URI accessible by the Algorithmia service & write to disk
- `algo_file_exists`: Test if a file exists
- `algo_options`: Set options for an algorithm call
- `algo_pipe`: Execute an Algorithmia algorithm call
- `algo_read_file`: Read a file from a URI accessible by the Algorithmia service
### TODO
- Finish file & dir functions
- Wrap things with `purrr::safely()`
- Craft something elegant for `output=void` option
- Test with more gnarly endpoints (somewhat done)
- Finish documentation (nearly done)
### Installation
```{r eval=FALSE}
devtools::install_github("hrbrmstr/algorithmia")
```
```{r echo=FALSE, message=FALSE, warning=FALSE, error=FALSE}
options(width=120)
```
### Usage
```{r}
library(algorithmia)
# current verison
packageVersion("algorithmia")
```
### Test Results
```{r message=FALSE}
library(algorithmia)
library(testthat)
library(magrittr)
library(dplyr)
```
```{r cache=TRUE}
date()
algo_client() %>%
algo_call("demo", "Hello", "0.1.1") %>%
algo_options(30) %>%
algo_pipe("there", "text")
# Have to provide some assistance to `httr` if the input is not a named list
# and the content type is set to "json"
algo_client() %>%
algo_call("demo", "Hello", "0.1.1") %>%
algo_options(30) %>%
algo_pipe('"there"', "json")
algo_client() %>%
algo_dir_exists("s3://public-r-data/")
algo_client() %>%
algo_dir_list("s3://public-r-data/")
algo_client() %>%
algo_file_exists("s3://public-r-data/ghcran.json")
algo_client() %>%
algo_read_file("s3://public-r-data/ghcran.json", fmt="parsed") -> cran
str(cran[[1]])
txt <- "A purely peer-to-peer version of electronic cash would allow online payments to be sent directly from one party to another without going through a financial institution. Digital signatures provide part of the solution, but the main benefits are lost if a trusted third party is still required to prevent double-spending. We propose a solution to the double-spending problem using a peer-to-peer network. The network timestamps transactions by hashing them into an ongoing chain of hash-based proof-of-work, forming a record that cannot be changed without redoing the proof-of-work. The longest chain not only serves as proof of the sequence of events witnessed, but proof that it came from the largest pool of CPU power. As long as a majority of CPU power is controlled by nodes that are not cooperating to attack the network, they'll generate the longest chain and outpace attackers. The network itself requires minimal structure. Messages are broadcast on a best effort basis, and nodes can leave and rejoin the network at will, accepting the longest proof-of-work chain as proof of what happened while they were gone."
algo_client() %>%
algo_call("nlp", "Summarizer", "0.1.3") %>%
algo_pipe(txt, "text")
URL <- 'rud.is/b/2016/07/12/slaying-cidr-orcs-with-triebeard-a-k-a-fast-trie-based-ipv4-in-cidr-lookups-in-r/'
algo_client() %>%
algo_call("util", "Html2Text", "0.1.4") %>%
algo_pipe(URL, "text")
bits <- list("This is a test of what this is. Hopefully this is going to work well as a test.", 2, 5, FALSE, TRUE)
out <- algo_client() %>%
algo_call("WebPredict", "GetNGramFrequencies", "0.1.1") %>%
algo_pipe(bits, "json")
bind_rows(out$result)
algo_client() %>%
algo_call("TimeSeries", "TimeSeriesSummary", "0.1.2") %>%
algo_pipe(list(uniformData=as.double(USAccDeaths)), "json")
# matches the `base::svd()` example
hilbert <- function(n) { i <- 1:n; 1 / outer(i - 1, i, "+") }
X <- hilbert(9)[, 1:6]
algo_client() %>%
algo_call("joannetang", "SVD", "0.1.0") %>%
algo_pipe(X, "json") -> svd_out
matrix(unlist(svd_out$result$U), ncol=6, byrow=TRUE)
```