Wednesday, January 20, 2016

My Vehicle History 1996 - 2015

Here's a post under the "and things" category in the Stats and things blog... it's my vehicle history. Note, only the Lexus picture is my actual vehicle. The others are the closest thing I could find in a quick google search.
1985 Toyota Cressida - Bought from a mechanic friend of my uncle. It was his Mom's car, she blew the engine. He fixed it up and sold it to me for $2,800ish. Good car until air conditioning, transmission problems and rusty suspension components made it too expensive to fix.
1986 Mercury Grand Marquis - Bought this from family. It was my great Grandpa's car from Florida. It was beige. It was old, but I got it with 78,000 miles. I put a subwoofer in the trunk. Somebody must have heard it, because they broke into it and stole everything. It was a crushing blow during my summer home from college. It ran great for me, but I wanted something a little more modern.
1994 Ford Explorer - My Mom's old car. She sold it to me for $5,000. I got a loan for most of that. It was awesome and got me through grad school. When the air conditioning went out and the forecast was predicting weather in the 90's, I traded it in for the Civic.
2003 Honda Civic ex - My first new vehicle. It was a black EX with a moon roof and 5-speed. I put 117,000 miles on it and sold it to a guy to give to his son for his 16th birthday. I had to have a strut replaced and the head gasket, timing belt, water pump. Very reliable vehicle.
2005 Nissan Xterra - We bought this new for my wife. It was the "off road" package in yellow. The off road package had a locking rear diff, but Erica wanted that package for the moulded stripe on the doors. Another very reliable vehicle. I think all I did on this one was a u-joint. We put 155,000 miles on it and sold it to a guy from down south. He flew up here to drive it back home.
1998 Chevy 2500 6.5L - I bought this when I had my Civic. I had a house and it was tough to get house stuff in the Civic. It was the 6.5L diesel engine with an extended cab and 8 foot bed. It was long and slow, but it got 18mpg. Things started to rust on this one. First, a rear brake line broke in the cold. Then the brake booster started to leak. Then the fuel tank rusted through and leaked diesel in my driveway. I sold it to a young kid with all of those things fixed at around 190,000 miles. Still ran great.
2004 Volkswagen Touareg - Got this to replace the Xterra for Erica. It was $15,500 with just 33,000 miles on it. That's because the first year Touaregs were riddled with problems. But it had all the options, V8, air ride, moon roof... it was awesome. I bought a warranty and had to use it when the vehicle wouldn't shut off even after we took the key out. A new ECU fixed that, but that was the only problem we had with it. Sold it at 80,000 miles to a guy from down south when the warranty ran out and the timing belt was due to be changed.
2010 Toyota Tundra - My current truck. I wanted the 5.7L engine, 4x4, and double cab. Ended up getting that in a base model work truck. Vinyl seats, rubber floor, and column shifter. Perfection. Bought it for $22,000 with 32,000 miles from a dentist in Michigan. He was coincidentally buying a motor home in Illinois, so I met him and bought it from him with cash at the motor home shop. It's had a new front differential and a whole new bed replaced under warranty. Still going at 88,000 miles
2011 Volkswagen Jetta Sportwagen TDI - I flew to Washington DC to buy this one with 6,000 miles on it for Erica to replace the Touareg. It gets 40mpg with the TDI engine. Unfortunately, the EPA has found out that VW cheated on the emissions tests with this engine and it's value has tanked. We are waiting to see what they do with the recall / buy back. It's at 111,000 miles now with only a couple minor warranty repairs.
1992 Lexus SC300 - Bought this from my uncle in pristine condition. It's a factory 5-speed with around 125,000 miles. I am saving money to add a turbo to it and bump up the horsepower from a stock 225hp to somewhere in the 400hp range.

Wednesday, May 27, 2015

Creating Styled Google Maps in ggmap

In R, my go to package for creating maps is ggmap. Using this, one can create maps using a variety of services, including Google maps. I just recently discovered the ability to create a styled version of a Google map. Let's go through this process to create a black and white map of Chicago, with the parks shown in red.

First, go to the Styled Maps Wizard and type in “Chicago IL”.



You are shown the stock Google map of Chicago, with some sliders to change various attributes of the map.


Let's take the “saturation” slider down to -100 and bump up the “gamma” slider to .5.


Then, we can work on making the parks red. First, click the “Add” button on the right side.


Next, on the left side at the top, choose “Point of Interest”, then “Park”.


Then, click the “Color” box and type in “#ff0000” into the box to specify red for the parks You should see the parks highlighted in red now.


The last thing we need is to grab the JSON for these styles. On the right side, at the bottom of the “Map Style” box, click “Show JSON”.


With this JSON, we can create the map in ggmaps.

library("RJSONIO")
library("ggmap")
library("magrittr")
style <- '[
  {
    "stylers": [
      { "saturation": -100 },
      { "gamma": 0.5 }
    ]
  },{
    "featureType": "poi.park",
    "stylers": [
      { "color": "#ff0000" }
    ]
  }
]'
style_list <- fromJSON(style, asText=TRUE)

create_style_string<- function(style_list){
  style_string <- ""
  for(i in 1:length(style_list)){
    if("featureType" %in% names(style_list[[i]])){
      style_string <- paste0(style_string, "feature:", 
                             style_list[[i]]$featureType, "|")      
    }
    elements <- style_list[[i]]$stylers
    a <- lapply(elements, function(x)paste0(names(x), ":", x)) %>%
           unlist() %>%
           paste0(collapse="|")
    style_string <- paste0(style_string, a)
    if(i < length(style_list)){
      style_string <- paste0(style_string, "&style=")       
    }
  }  
  # google wants 0xff0000 not #ff0000
  style_string <- gsub("#", "0x", style_string)
  return(style_string)
}

style_string <- create_style_string(style_list)
mymap <- ggmap(get_googlemap("chicago", size=c(800,800), style=style_string), extent="device")
ggsave(filename="pics/mymap.png", width=8, height=8)



I wrote the helper function “create_style_string” to take the style parameters given from Google as JSON, and create a string to use in the API request. Put that style_string in the “style” parameter in get_googlemap() and you get your map back.

The possibilities are endless to create maps with colored placenames, water, places of interest, etc. Very cool stuff.

Thursday, March 26, 2015

fitbitScraper 0.1.2 Now on CRAN

I've updated the fitbitScraper to 0.1.2 with the help of a friend that gave me access to his fitbit account so I could work out the heart rate API endpoints (thanks Shane!). This is a package that enables you to read daily or intraday data from Fitbit into R for graphing and analysis.

Here's some examples:

I'll download all my steps for last Saturday, March 21, 2015, then make a graph similar to how it appears on the fitbit dashboard. As you can see, I spent some time playing basketball in the morning and pretty much took it easy the rest of the day. Note that the function name has changed to get_intraday_data() from get_15_min_data() in version 0.1.1.

# install.packages("fitbitScraper")  
library("fitbitScraper")
# just reading from file to hide pw and to make .Rmd document to work...
creds <- readLines("pw.txt")
cookie <- login(email=creds[1], password=creds[2]) 
df <- get_intraday_data(cookie, what="steps", date="2015-03-21")  
library("ggplot2")  
ggplot(df) + geom_bar(aes(x=time, y=steps, fill=steps), stat="identity") + 
             xlab("") +ylab("steps") + 
             theme(axis.ticks.x=element_blank(), 
                   panel.grid.major.x = element_blank(), 
                   panel.grid.minor.x = element_blank(), 
                   panel.grid.minor.y = element_blank(), 
                   panel.background=element_blank(), 
                   panel.grid.major.y=element_line(colour="gray", size=.1), 
                   legend.position="none") 

plot of chunk unnamed-chunk-1

Now, let's take a look at the heart rate data. This is Shane's data… I have no idea what he was doing on this day. Note that whereas intraday data for steps is given in 15 minute intervals, fitbit provides the heart rate data in 5 minute intervals.

# just reading from file to hide pw and to make .Rmd document to work...
creds <- readLines("pw2.txt")
cookie <- login(email=creds[1], password=creds[2]) 
df <- get_intraday_data(cookie, what="heart-rate", date="2015-03-20")
library("ggplot2")  
ggplot(df) + geom_bar(aes(x=time, y=`heart-rate`, fill=`heart-rate`,
                          colour=`heart-rate`), stat="identity") + 
             xlab("") +ylab("heart-rate") + 
             theme(axis.ticks.x=element_blank(), 
                   panel.grid.major.x = element_blank(), 
                   panel.grid.minor.x = element_blank(), 
                   panel.grid.minor.y = element_blank(), 
                   panel.background=element_blank(), 
                   panel.grid.major.y=element_line(colour="gray", size=.1), 
                   legend.position="none") 

plot of chunk unnamed-chunk-3

And finally, the daily heart rate data comes with three data points for each day. Zone1, zone2, and zone3 presumably represent the time in a given heart rate zone. I suspect they correspond to “fat burn zone”, “cardio zone”, and “peak zone” respectively. More information on fitbit heart rate zones is available here.

# just reading from file to hide pw and to make .Rmd document to work...
creds <- readLines("pw2.txt")
cookie <- login(email=creds[1], password=creds[2]) 
df <- get_daily_data(cookie, what="getTimeInHeartRateZonesPerDay", 
                     start_date="2015-02-17", end_date="2015-02-23")
library("reshape")
df <- melt(df, id="time", variable_name="zone_num")
library("ggplot2")  
ggplot(df) + geom_bar(aes(x=time, y=value, fill=zone_num), 
                      position=position_dodge(), stat="identity") + 
             xlab("Date") +ylab("Minutes in Zone") + 
             theme(axis.ticks.x=element_blank(), 
                   panel.grid.major.x = element_blank(), 
                   panel.grid.minor.x = element_blank(), 
                   panel.grid.minor.y = element_blank(), 
                   panel.background=element_blank(), 
                   panel.grid.major.y=element_line(colour="gray", size=.1)) 

plot of chunk unnamed-chunk-4

I'd love to work out the details for the GPS in the fitbit Surge. Unfortunately, I don't have one. If you are interested in working with me on integrating that data into the package, hit me up… corynissen@gmail.com

Thursday, January 22, 2015

R Package to Download Fitbit Data

Edit 4/8/2015: Updated to use newer functions…
Edit 3/26/2015: fitbitScraper 0.1.2 is now on CRAN with new heart rate data capabilities.
Edit 2/2/2015: fitbitScraper 0.1.1 is now on CRAN

Fitbit is a device that tracks your daily activity. It's basically a pedometer, but it does a little more. It has an altimeter, so it can count flight of stairs climbed. It can detect your sleeping activity and give you a read on how often you are tossing and turning. Any how, I received a Fitbit One for Christmas and have been unexpectedly into this thing. I absolutely did not expect to be motivated by monitoring my fitness activity. It's been fun.

The problem is that Fitbit doesn't allow you to export your data under their “free” data tracking tier. It costs $50 a month to upgrade to “premium” to allow for data export. It's my data, I should be able to get it. So, I made an R package to do just that.

fitbitScraper is my new R package, hosted on Github for now, to download Fitbit data. It uses the internal API that fitbit uses to populate your dashboard. Here, they give data as granular as every 15 minutes. Also, there's daily aggregate data available. Basically, the package logs into fibit.com using your email / password, and is returned a cookie. Using that cookie, the internal API is accessible. For the time being, I can only get that cookie if you use email / password to login. Facebook and Google login are available, but I haven't put any effort into figuring out how to get a cookie if one of those methods are used to login. One could copy and paste their cookie information into R and use this package that way…

Here's a quick example of downloading and graphing step data for a given day. On this particular day, I played basketball from about 6am until 9am.

install.packages("fitbitScraper")  
library("fitbitScraper")
# just reading from file to hide pw and to make .Rmd document to work...
mypassword <- readLines("pw.txt")
cookie <- login(email="corynissen@gmail.com", password=mypassword) 
df <- get_intraday_data(cookie, what="steps", date="2015-01-10")  
library("ggplot2")  
ggplot(df) + geom_bar(aes(x=time, y=steps, fill=steps), stat="identity") + 
             xlab("") +ylab("steps") + 
             theme(axis.ticks.x=element_blank(), 
                   panel.grid.major.x = element_blank(), 
                   panel.grid.minor.x = element_blank(), 
                   panel.grid.minor.y = element_blank(), 
                   panel.background=element_blank(), 
                   panel.grid.major.y=element_line(colour="gray", size=.1), 
                   legend.position="none") 

plot of chunk unnamed-chunk-1

Here's an example of the daily data.

df <- get_daily_data(cookie, what="steps", start_date="2015-01-13", end_date="2015-01-20")  
library("ggplot2")  
ggplot(df) + geom_bar(aes(x=time, y=steps), stat="identity") + 
             xlab("") +ylab("steps") + 
             theme(axis.ticks.x=element_blank(), 
                   panel.grid.major.x = element_blank(), 
                   panel.grid.minor.x = element_blank(), 
                   panel.grid.minor.y = element_blank(), 
                   panel.background=element_blank(), 
                   panel.grid.major.y=element_line(colour="gray", size=.1), 
                   legend.position="none") 

plot of chunk unnamed-chunk-2

I have to give a should out to this guy for inspiration. I don't know perl, so I couldn't really use anything here, but it gave me confidence that I could figure it out.

I hope this is of some use to some of you R hackers out there…

Thursday, January 8, 2015

Using rvest to Scrape an HTML Table

I recently had the need to scrape a table from wikipedia. Normally, I'd probably cut and paste it into a spreadsheet, but I figured I'd give Hadley's rvest package a go.

The first thing I needed to do was browse to the desired page and locate the table. In this case, it's a table of US state populations from wikipedia. Rvest needs to know what table I want, so (using the Chrome web browser), I right clicked and chose “inspect element”. This splits the page horizonally. As you hover over page elements in the html on the bottom, sections of the web page are highlighted on the top.

Hovering over the blue highlighted line will cause the table on top to be colored blue. This is the element we want. I clicked on this line, and choose “copy XPath”, then we can move to R.

First step is to install rvest from CRAN.

install.packages("rvest")

Then we it's pretty simple to pull the table into a dataframe. Paste that XPath into the appropriate spot below.

library("rvest")
url <- "http://en.wikipedia.org/wiki/List_of_U.S._states_and_territories_by_population"
population <- url %>%
  html() %>%
  html_nodes(xpath='//*[@id="mw-content-text"]/table[1]') %>%
  html_table()
population <- population[[1]]

head(population)
##   Rank in\nthe Fifty\nStates,\n2014
## 1                           !000001
## 2                           !000002
## 3                           !000003
## 4                           !000004
## 5                           !000005
## 6                           !000006
##   Rank in all\nstates\n& terri-\ntories,\n2010 State or territory
## 1                                      !000001         California
## 2                                      !000002              Texas
## 3                                      !000004            Florida
## 4                                      !000003           New York
## 5                                      !000005           Illinois
## 6                                      !000006       Pennsylvania
##   Population estimate for\nJuly 1, 2014 Census population,\nApril 1, 2010
## 1                            38,802,500                        37,253,956
## 2                            26,956,958                        25,145,561
## 3                            19,893,297                        18,801,310
## 4                            19,746,227                        19,378,102
## 5                            12,880,580                        12,830,632
## 6                            12,787,209                        12,702,379
##   Census population,\nApril 1, 2000 Seats inU.S. House,\n2013–2023
## 1                        33,871,648                        !000053
## 2                        20,851,820                        !000036
## 3                        15,982,378                        !000027
## 4                        18,976,457                        !000027
## 5                        12,419,293                        !000018
## 6                        12,281,054                        !000018
##   Presi-\ndential\nElectors\n2012–\n2020
## 1                                !000055
## 2                                !000038
## 3                                !000029
## 4                                !000029
## 5                                !000020
## 6                                !000020
##   2014 Estimated pop.\nper\nHouse seat
## 1                              732,123
## 2                              748,804
## 3                              736,789
## 4                              731,342
## 5                              715,588
## 6                              710,401
##   2010 Census pop.\nper\nHouse\nseat[4] 2000 Census pop.\nper\nHouse\nseat
## 1                               702,905                            639,088
## 2                               698,487                            651,619
## 3                               696,345                            639,295
## 4                               717,707                            654,361
## 5                               712,813                            653,647
## 6                               705,688                            646,371
##   Percent\nof total\nU.S. pop.,\n2014[5]
## 1                                 12.17%
## 2                                  8.45%
## 3                                  6.24%
## 4                                  6.19%
## 5                                  4.04%
## 6                                  4.01%

There's some work to be done on column names, but this is a pretty pain free way to scrape a table. As usual, a big shout out to Hadley Wickham for making this so easy for us.

Thursday, November 6, 2014

geocodeHERE 0.1 is on CRAN

In my previous blog post, I detailed how I created my first R package called geocodeHERE. This package is a convenient wrapper for Nokia's HERE geocoding API. The cool thing about this API is that it allows for bulk geocoding. So, instead of doing n API calls to geocode n addresses, you can do it with just a couple API calls. Also, you can run 10,000 API calls per day vs. Google's 2,500.

Any how, I went through the process to submit the package to CRAN and it was accepted. It took me 3 attempts, but I did it and it should be replicated across the mirrors by now. You can check it out on CRAN here.

Here's how it works, starting with downloading and installing the package (you'll need the httr package installed)…

install.packages("geocodeHERE", repo="http://cran.rstudio.com",
                 dependencies=TRUE)  
## Installing package into ‘/home/c/R/x86_64-pc-linux-gnu-library/3.1’
## (as ‘lib’ is unspecified)
## trying URL 'http://cran.rstudio.com/src/contrib/geocodeHERE_0.1.tar.gz'
## ...
## * DONE (geocodeHERE)

Now, we can try to run some simple queries. Given an address or place name, it will return the latitude, longitude, or NA if it can't find anything

library(geocodeHERE)  
geocodeHERE_simple("wrigley field chicago IL")
## $Latitude
## [1] 41.95
## 
## $Longitude
## [1] -87.65
geocodeHERE_simple("navy pier chicago IL")
## $Latitude
## [1] 41.94
## 
## $Longitude
## [1] -87.7
geocodeHERE_simple("the bean chicago IL")
## [1] NA

That's kinda boring though. There exists functions in other packages to do this same thing, namely ggmap::geocode(). What's interesting about Nokia HERE's API is that you can do gecoding of many addresses in bulk.

data(chicago_landmarks)
addresses <- chicago_landmarks[,"Address"]
# tack on "chicago IL" to the end of these addresses
addresses <- paste(addresses, "chicago IL")
# make a dataframe with an id column so you can match the lat, lngs back
addresses_df <- data.frame(id=1:length(addresses), addresses=addresses)
str(addresses_df)
## 'data.frame':    375 obs. of  2 variables:
##  $ id       : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ addresses: Factor w/ 374 levels "1001 W. Belmont Avenue chicago IL",..: 127 149 160 161 345 290 312 206 318 203 ...
address_str <- df_to_string(addresses_df)
request_id <- geocodeHERE_batch_upload(address_string = address_str,
                                       email_address = "test@test.com")
# wait about 15 seconds... status should go from "running" to "completed"
Sys.sleep(15)
geocodeHERE_batch_status(request_id)
## [1] "completed"
# download the data
geocode_data <- geocodeHERE_batch_get_data(request_id)
# match it back to your original addresses dataframe
addresses_df <- merge(addresses_df, geocode_data, by.x="id", by.y="recId", all.x=T)
str(addresses_df)
## 'data.frame':    375 obs. of  16 variables:
##  $ id              : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ addresses       : Factor w/ 374 levels "1001 W. Belmont Avenue chicago IL",..: 127 149 160 161 345 290 312 206 318 203 ...
##  $ SeqNumber       : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ seqLength       : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ displayLatitude : num  41.9 41.9 41.9 41.9 41.8 ...
##  $ displayLongitude: num  -87.6 -87.6 -87.6 -87.6 -87.6 ...
##  $ houseNumber     : int  300 333 35 3600 NA 6901 860 4605 9326 4550 ...
##  $ street          : chr  "W Adams St" "N Michigan Ave" "E Wacker Dr" "N Halsted St" ...
##  $ district        : chr  "Loop" "Loop" "Loop" "Lake View" ...
##  $ city            : chr  "Chicago" "Chicago" "Chicago" "Chicago" ...
##  $ postalCode      : int  60606 60601 60601 60613 60637 60649 60611 60640 60643 60640 ...
##  $ county          : chr  "Cook" "Cook" "Cook" "Cook" ...
##  $ state           : chr  "IL" "IL" "IL" "IL" ...
##  $ country         : chr  "USA" "USA" "USA" "USA" ...
##  $ matchLevel      : chr  "houseNumber" "houseNumber" "houseNumber" "houseNumber" ...
##  $ relevance       : num  1 1 1 1 0.63 1 0.99 1 1 1 ...

All of the previous commands were done under the DEMO license keys. If you are going to use this a lot, it's probably best to get your own API keys. You can do that here.

If you have any questions, hit me up on twitter or shoot me an email at corynissen_AT_gmail.com

Thursday, October 23, 2014

Making an R Package to use the HERE geocode API

HERE is a product by Nokia, formerly called Nokia maps and before that, Ovi maps. It's the result of the acquisition of NAVTEQ in 2007 combined with Plazes and Metacarta, among others. It has a geocoding API, mapping tiles, routing services, and other things. I'm focused on the geocoding service. Under the “Base” license, you can run 10,000 geocoding requests per day. According to wikipedia, that is the most among the free geocoding services. On top of that, HERE does bulk encoding where you submit a file of things to geocode and it returns a link to download a file of results. This sure beats making thousands of requests one at a time.

I figured coding up a quick function to use this service would be the perfect reason to build my first R package. So, after getting my HERE API keys, I fired up devtools and got started with the R package.

First, I had to install the latest version of devtools and roxygen2

install.packages("devtools", repos="http://cran.rstudio.com/")
install.packages("roxygen2", repos="http://cran.rstudio.com/")
library(devtools)
library(roxygen2)

Next, I chose a directory, and ran the create() function from devtools. This creates a package skeleton that contains the basic structure needed for an R package.

devtools::create("geocodeHERE")

Several files and directories are created after running create(). I moved over to the 'R' directory and created a file called “geocodeHERE_simple.R”. I put my function to use the HERE geocoding API in there. This function was designed to be minimalist and similar to the ggmap geocode() function.

#' Attempt to geocode a string
#'
#' Enter a string and have latitude and longitude returned using the HERE API
#' @param search A string to search
#' @param App_id App_id to use the production HERE API. Get one here... http://developer.here.com/get-started. If left blank, will default to demo key with an unknown usage limit.
#' @param App_code App_code to use the production HERE API. Get one here... http://developer.here.com/get-started. If left blank, will default to demo key with an unknown usage limit.
#' @keywords geocode
#' @export
#' @examples
#' \dontrun{
#' geocodeHERE_simple("chicago")
#' geocodeHERE_simple("wrigley field chicago IL")
#' geocodeHERE_simple("233 S Wacker Dr, Chicago, IL 60606")
#' }
#' geocodeHERE_simple
geocodeHERE_simple <- function(search, App_id="", App_code=""){
  if(!is.character(search)){stop("'search' must be a character string")}
  if(!is.character(App_id)){stop("'App_id' must be a character string")}
  if(!is.character(App_code)){stop("'App_code' must be a character string")}

  if(App_id=="" & App_code==""){
    App_id <- "DemoAppId01082013GAL"
    App_code <- "AJKnXv84fjrb0KIHawS0Tg"
    base_url <- "http://geocoder.cit.api.here.com/6.2/geocode."
  }else{
    base_url <- "http://geocoder.api.here.com/6.2/geocode."
  }

  search <- RCurl::curlEscape(search)

  final_url <- paste0(base_url, format, "?app_id=", ids$App_id, "&app_code=",
                      ids$App_code, "&searchtext=", search)

  response <- RCurl::getURL(final_url)
  response_parsed <- RJSONIO::fromJSON(response)
  if(length(response_parsed$Response$View) > 0){
    ret <- response_parsed$Response$View[[1]]$Result[[1]]$Location$DisplayPosition
  }else{
    ret <- NA
  }
  return(ret)
}

Note the text on the top of the code. That is added in order to automatically create help documentation for the function.

Now, if you look closely, I am using two other packages in that function… RCurl and RJSONIO. Also, notice that I'm not making any library() calls. This must be done in the DESCRIPTION file that is automatically generated by create(). In addition to calling out what packages to import, you input the package name, author, description, etc.

Package: geocodeHERE
Title: Wrapper for the HERE geocoding API
Version: 0.1
Authors@R: "Cory Nissen <corynissen@gmail.com> [aut, cre]"
Description: Wrapper for the HERE geocoding API
Depends:
    R (>= 3.1.1)
License: MIT
LazyData: true
Imports:
    RJSONIO,
    RCurl

Then, I set my working directory to the package root and ran the document() function from devtools that automatically creates package documentation.

setwd("geocodeHERE")
document()

From this point, you can upload your package to github and use install_github(), or use the install() function to install your package locally.

setwd("..")
install()

As far as the HERE geocoding API goes, I find it pretty decent at doing “fuzzy matching”. That is, given a place name instead of an address, it does a good job of correctly returning the coordinates. The downside is that you must register for an API key, where Google does not require registration to use it's geocoding service. But, you only get 2500 requests per day via Google, HERE offers 10,000 per day.

Any how, a big shout out to Hilary Parker for her blog post on creating an R package using devtools, Hadley Wickham for the devtools package (among others), and RStudio for the fantastic and free (and open source) IDE for R.

The geocodeHERE package is available on github. I'll be adding bulk geocoding functionality as time permits. You can install the package with the following code:

devtools::install_github("corynissen/geocodeHERE")
library(geocodeHERE)
geocodeHERE_simple("wrigley field chicago il")