Code Monkey home page Code Monkey logo

Comments (2)

bransonf avatar bransonf commented on August 14, 2024 1

@lepromatous It is in fact the Non-standard evaluation that makes it difficult to put this function within another function. Providing an example is much appreciated. One solution to the problem here is to force quotation of the input, and then take advantage of quasiquotation using !!. Tidy evaluation, as it's called, is still difficult for me to explain well. If you're interested in learning more Read This

### SOME DATA
data<-data.frame(Address = c("4643 Lindell Blvd", "3545 Lafayette Ave"), City = c("St. Louis", "St. Louis"), State = c("MO", "MO"), ZIP.Code = c(63108, 63104) )

#### BEGIN FUNCTION
geocodeme<-function(data, StateSub, Street.col, City.col, State.col, Zip.col){
  
  #### state subset
  
  sub<-subset(data, toupper(data[,rlang::quo_name(rlang::enquo(State.col))])%in%toupper(StateSub))
  
  require("censusxy") || install.packages("censusxy")
  library(censusxy)
  
  ##### GEOCODE

  Street.col <- rlang::quo_name(rlang::enquo(Street.col))
  City.col <- rlang::quo_name(rlang::enquo(City.col))
  State.col <- rlang::quo_name(rlang::enquo(State.col))
  Zip.col <- rlang::quo_name(rlang::enquo(Zip.col))
  
  
  results <- cxy_geocode(sub, address = !!Street.col, city = !!City.col, state = !!State.col, zip= !!Zip.col, style="full", output="sf")
  
  require("tigris") || install.packages("tigris")
  library(tigris)
  
  require("sf") || install.packages("sf")
  library(sf)
  
  ### pull state
  shp<-block_groups(toupper(StateSub), class="sf")
  
  #### set projection
  results <- sf::st_transform(results, "+proj=longlat +datum=WGS84")
  shp <- sf::st_transform(shp, "+proj=longlat +datum=WGS84")
  
  require("spatialEco") || install.packages("spatialEco")
  library(spatialEco)
  
  out<-point.in.poly(results, shp)
  rm(shp)
  rm(results)
  return(out)
  
}
#### END FUNCTION

### run function
blah<-geocodeme(data, StateSub="MO", Street.col=Address, City.col=City, State.col=State, Zip.col=ZIP.Code)

from censusxy.

chris-prener avatar chris-prener commented on August 14, 2024

Thanks @lepromatous! @bransonf - lets talk about this today.

from censusxy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.