Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit 072afce

Browse files
committed
Merge pull request #23 from ropensci/geojson
Added a new function called gist_map
2 parents f4eaec4 + 616a2cc commit 072afce

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Description: Work with GitHub gists from R (e.g.,
99
your default browser, get embed code for a gist, list gist commits, and
1010
get rate limit information when authenticated. Some requests require
1111
authentication and some do not. Gists website: https://gist.github.com/.
12-
Version: 0.1.1.99
12+
Version: 0.1.2.99
1313
Date: 2015-01-16
1414
Authors@R: c(person("Ramnath", "Vaidyanathan", role = "aut",
1515
email = "ramnath.vaidya@gmail.com"),
@@ -25,6 +25,7 @@ Imports:
2525
jsonlite,
2626
httr,
2727
magrittr,
28+
assertthat,
2829
knitr
2930
Suggests:
3031
roxygen2,

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export(forks)
2020
export(gist)
2121
export(gist_auth)
2222
export(gist_create)
23+
export(gist_map)
2324
export(gists)
2425
export(rate_limit)
2526
export(rename_files)
@@ -29,6 +30,7 @@ export(star_check)
2930
export(unstar)
3031
export(update)
3132
export(update_files)
33+
import(assertthat)
3234
import(httr)
3335
import(knitr)
3436
importFrom(magrittr,"%>%")

R/gist_map.R

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
3+
#' Opens a full screen map after uploading a geojson file
4+
#'
5+
#'Takes a gist object and a input geojson file name and renders fullscreen map
6+
#' @param file Must be a geojson file
7+
#' @param gist_object An object of class \code{gist_id} generated by \code{gist_create}
8+
#' @param browse Default is \code{TRUE}. Set to \code{FALSE} if you don't want to automatically browse to the URL.
9+
#' @export
10+
#' @import assertthat
11+
#' @examples \dontrun{
12+
#' library(ecoengine)
13+
#' x <- ee_observations(genus = "vulpes")
14+
#' ee_map(x, dest = "~/Desktop")
15+
#' gist_id <- gist_create(files = "~/Desktop/temp.geojson", browse = FALSE)
16+
#' gist_map(file = "temp.geojson", gist_id)
17+
#'
18+
#'}
19+
gist_map <- function(file = NULL, gist_object, browse = TRUE) {
20+
21+
assertthat::assert_that(has_extension(file, "geojson"))
22+
23+
render_url <- "https://render.githubusercontent.com/view/geojson/?url=https://gist.githubusercontent.com/"
24+
point <- length(gist_object$history)
25+
version <-gist_object$history[[point]]$version
26+
full_path <- gist_object$history[[point]]$url
27+
user <- gist_object$history[[point]]$user$login
28+
commit <- gsub("https://api.github.com/gists/", "", full_path)
29+
actual_commit <- strsplit(commit, "/")[[1]][1]
30+
path <- paste(render_url, user, actual_commit, "raw", file, sep = "/")
31+
if(browse) {
32+
browseURL(path)
33+
} else {
34+
path
35+
}
36+
}

man/gist_map.Rd

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
% Generated by roxygen2 (4.1.0): do not edit by hand
2+
% Please edit documentation in R/gist_map.R
3+
\name{gist_map}
4+
\alias{gist_map}
5+
\title{Opens a full screen map after uploading a geojson file}
6+
\usage{
7+
gist_map(file = NULL, gist_object, browse = TRUE)
8+
}
9+
\arguments{
10+
\item{file}{Must be a geojson file}
11+
12+
\item{gist_object}{An object of class \code{gist_id} generated by \code{gist_create}}
13+
14+
\item{browse}{Default is \code{TRUE}. Set to \code{FALSE} if you don't want to automatically browse to the URL.}
15+
}
16+
\description{
17+
Takes a gist object and a input geojson file name and renders fullscreen map
18+
}
19+
\examples{
20+
\dontrun{
21+
library(ecoengine)
22+
x <- ee_observations(genus = "vulpes")
23+
ee_map(x, dest = "~/Desktop")
24+
gist_id <- gist_create(files = "~/Desktop/temp.geojson", browse = FALSE)
25+
gist_map(file = "temp.geojson", gist_id)
26+
27+
}
28+
}
29+

0 commit comments

Comments
 (0)