Skip to content

Commit

Permalink
Merge pull request #4 from DavidASmith/dev
Browse files Browse the repository at this point in the history
Fixed API key exposure, prepared for CRAN submission
  • Loading branch information
DavidASmith committed Sep 30, 2023
2 parents 43f11be + 5a92dc7 commit 8751675
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 21 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
^docs$
^pkgdown$
^\.github$
^cran-comments\.md$
9 changes: 5 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
Package: whatthreewords
Title: Work with the what3words API for easy location referencing.
Version: 0.1.0
Title: Work with the What3words API for Easy Location Referencing
Version: 0.1.1
Authors@R:
person("David", "Smith", , "david.alex.smith@gmail.com",
role = c("aut", "cre"),
comment = c(ORCID = "0009-0000-8482-3220"))
Description: Use the what3words API to return three words which uniquely
identify every 3m x 3m square on Earth. Also possible to return coordinates
from any valid three words location. Supports multiple languages.
identify every 3m x 3m square on Earth. It is also possible to return
coordinates from any valid three words location. Supports multiple
languages.
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# whatthreewords 0.1.1

* Fixed `get_api_key()` example exposing API key in documentation.

# whatthreewords 0.1.0

* Initial release.
2 changes: 1 addition & 1 deletion R/get_api_key.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' @export
#'
#' @examples
#' get_api_key()
#' \dontrun{get_api_key()}
get_api_key <- function() {
key <- Sys.getenv("WTW_API_KEY")
if (identical(key, "")) {
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ coords_from_words("hours.flesh.petal")

## Alternative packages

There is an alternative R client for what3words available on [CRAN](https://cran.r-project.org/web/packages/threewords/index.html) ([Github repo](https://github.com/Ironholds/threewords)). However, this has not been updated (at time of writing) for several years and I couldn't get it to work. I needed something fairly quickly so wrote this from scratch.
There is an alternative R client for what3words available on [CRAN](https://CRAN.R-project.org/package=threewords) ([Github repo](https://github.com/Ironholds/threewords)). However, this has not been updated (at time of writing) for several years and I couldn't get it to work. I needed something fairly quickly so wrote this from scratch.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ coords_from_words("hours.flesh.petal")
## Alternative packages

There is an alternative R client for what3words available on
[CRAN](https://cran.r-project.org/web/packages/threewords/index.html)
([Github repo](https://github.com/Ironholds/threewords)). However, this
has not been updated (at time of writing) for several years and I
couldn’t get it to work. I needed something fairly quickly so wrote this
from scratch.
[CRAN](https://CRAN.R-project.org/package=threewords) ([Github
repo](https://github.com/Ironholds/threewords)). However, this has not
been updated (at time of writing) for several years and I couldn’t get
it to work. I needed something fairly quickly so wrote this from
scratch.
5 changes: 5 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## R CMD check results

0 errors | 0 warnings | 1 note

* This is a new release.
2 changes: 1 addition & 1 deletion man/get_api_key.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 18 additions & 9 deletions vignettes/usingwhatthreewords.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,22 @@ You must then set the `WTW_API_KEY` environment variable to hold your key. For e
Sys.setenv(WTW_API_KEY = "MYKEY")
```

```{r include=FALSE}
key_present <- tryCatch({
whatthreewords::get_api_key()
TRUE
},
error = function(e) FALSE)
```


You are now ready to use the package.

# Get a what3words address from coordinates

Use `words_from_coords` to get a what3words location for a given latitude and longitude.

```{r}
```{r eval=key_present}
words_from_coords(lat = 51.5095,
lon = -0.1266)
```
Expand All @@ -51,7 +60,7 @@ words_from_coords(lat = 51.5095,

By default, `words_from_coords` returns only the three words which represent the location. However, it's possible to return more information about the location by submitting `full_details = TRUE`.

```{r}
```{r eval=key_present}
words_from_coords(lat = 51.5095,
lon = -0.1266,
full_details = TRUE)
Expand All @@ -61,7 +70,7 @@ words_from_coords(lat = 51.5095,

`words_from_coords` is vectorised over the coordinates so you can return multiple locations with one call. For example, take the following data frame.

```{r}
```{r eval=key_present}
locations <- data.frame(name = c("Sheffield United", "Sheffield Wednesday", "Sheffield Club"),
lat = c(53.3703, 53.41145, 53.3096),
lon = c(-1.47119, -1.500204, -1.478715))
Expand All @@ -70,7 +79,7 @@ locations

We can add the what3words for each row like this...

```{r}
```{r eval=key_present}
locations$words <- words_from_coords(lat = locations$lat,
lon = locations$lon)
Expand All @@ -83,7 +92,7 @@ locations

`coords_from_words` returns the coordinates for a what3words location.

```{r}
```{r eval=key_present}
coords_from_words("hours.flesh.petal")
```
By default, coordinates are returned as a matrix with as many rows as the length of the vector submitted to the `words` argument.
Expand All @@ -92,7 +101,7 @@ By default, coordinates are returned as a matrix with as many rows as the length

You can also return the full details of the location as a list.

```{r}
```{r eval=key_present}
coords_from_words("hours.flesh.petal", full_details = TRUE)
```

Expand All @@ -101,7 +110,7 @@ coords_from_words("hours.flesh.petal", full_details = TRUE)
`coords_from_words` is vectorised over words. You can return multiple
coordinates like this:

```{r}
```{r eval=key_present}
coords_from_words(c("laughs.remind.fact",
"hotdog.jumping.frog",
"dream.helps.forget"))
Expand All @@ -111,15 +120,15 @@ coords_from_words(c("laughs.remind.fact",

what3words support a range of languages. You can work in different languages by submitting a supported [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) two letter code to `language`.

```{r}
```{r eval=key_present}
words_from_coords(lat = 48.70913,
lon = 9.001062,
language = "de")
```

Supported languages can be determined by `get_available_languages`.

```{r}
```{r eval=key_present}
get_available_languages() |>
head()
```

0 comments on commit 8751675

Please sign in to comment.