Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mutate_geocode() is incompatible with the behavior of tbl_df-type data frames #68

Merged
merged 1 commit into from
May 22, 2017

Conversation

dannguyen
Copy link
Contributor

If the data frame that is passed into mutate_geocode() happens to be a class of tbl_df (via dplyr, an error will arise due to tbl_df's different subsetting behavior.

Demonstration of error:
library(ggmap)
df <- data.frame(
  address = c("1600 Pennsylvania Avenue, Washington DC", "", "houston texas"),
  stringsAsFactors = FALSE
)
## Convert to tbl_df
tdf <- as_data_frame(df)
mutate_geocode(tdf, location = address, source = "google")
Error message:
  Error: is.character(location) is not TRUE
  In addition: Warning message:
  drop ignored 

I'm not sure of how often ggmap users will have a situation in which their data frames are actually tbl_dfs...all I know is that it happened to me on my very first spin of mutate_geocode :).

In the pull request I've made what I think fixes the issue without requiring the user to convert their tbl_df before running mutate_geocode(). I'm not sure if this works for all cases or introduces any other kind of breakage. Or if any of ggmap's other vector functions might need the same fix.

mutate_geocode() coerces the result into a data.frame...not sure if that should be changed in case a user is expecting tbl_df() back...

@crazybilly
Copy link

With regard to coercing the results to data.frame, ggmap is already importing dplyr::bind_cols. Couldn't we change the last line to the following to maintain the class of the original data frame?

bind_cols(data, gcdf)

@mine-cetinkaya-rundel
Copy link

Are there plans to merge this, or a similar fix that addresses the same issue?

@dkahle dkahle merged commit c38cc3b into dkahle:master May 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants