This site uses different types of cookies, including analytics and functional cookies (its own and from other sites). To change your cookie settings or find out more, click here. If you continue browsing our website, you accept these cookies.
I am attempting to use the R package tigris within an R tool, in order to retrieve geographies using the Census API. The attached R code (saved as txt to allow upload) works as expected in RStudio. Note that tigris is not a package included in the Predictive Analytics RInstaller, but the package is correctly installed and available to Alteryx. Running the R tool produces the following error: The Designer x64 reported: InboundNamedPipe GetOverlappedResults: The pipe has been ended.
Note that on occasion, the error message also includes "You have found a bug. Replicate, then let us know. We shall fix it soon." I opened a case, but was told that since the package is not part of the Predictive Analytics RInstaller that it is very unlikely the Dev team would address, so the case was closed.
Any advice on the potential issue would be helpful. @SydneyF -- I know you're one of the resident Alteryx-R gurus; perhaps you have an idea why this error is produced and potentially how it could be remedied?
Following should work in Alteryx Designer. Bear in mind that it is going to drop geometry. Depending on your goal with the data, this might not be the right solution for you.
## Code Example # Load the `tigris` package library(tigris)
# Use the `tracts`` function to download all tracts in a specific state and ounty tr_WI_Winnebago <- tigris::tracts( state = "WI", # Specify state county = "Winnebago", # Specify county year = 2019, # Specify year cb = FALSE) # Specify cartographic boundary (True) or TIGER Line/Shapefile (False)
library(sf) st_geometry(tr_WI_Winnebago) <- NULL
# In Alteryx, urite out to output anchors write.Alteryx(tr_WI_Winnebago, 1)
You're correct, tigris returns sf objects. Thanks for the clarification about Alteryx expecting a data frame. Your use of st_geometry() to set the geometry to null may come in handy with future analysis use cases, but unfortunately, the point of my current objective is precisely to acquire the geometries and use them in Alteryx.
Do you know of any way around this issue? Perhaps the sf object can be turned into something that Alteryx can understand, like a shapefile?
It uses package geojsonsf to convert geometry to geojson. This will allow you to convert geometry column to a spatial object.
## Code Example
# Load the `tigris` package
# Use the `tracts`` function to download all tracts in a specific state and ounty
tr_WI_Winnebago <- tigris::tracts(
state = "WI", # Specify state
county = "Winnebago", # Specify county
year = 2019, # Specify year
cb = FALSE) # Specify cartographic boundary (True) or TIGER Line/Shapefile (False)
# Convert geometry field to geojson
geometry <- sfc_geojson(tr_WI_Winnebago$geometry)
# Convert geometry list to a data.frame
geometry_df <- data.frame(geometry=matrix(unlist(geometry), nrow=length(geometry), byrow=T))
# Remove original geometry column
st_geometry(tr_WI_Winnebago) <- NULL
# Output original data frame without geometry column and converted column
Then, I would use a Select tool to convert geometry field to a Spatial Object:
I have attached the workflow as an example.
R is not my first programming language so feel free to adapt code and share the result!
2. That allowed me to join the original data (sans sf geometry) to the new geojson geometry data frame, rather than cbind--out of a concern for the possibility of the datasets getting out of order with one another (i.e., join rather than union by position).
tr_WI_Winnebago_geo <- tr_WI_Winnebago_removesf %>% inner_join(geometry_df, by = c("GEOID" = "GEOID"))
I attached an R Markdown (HTML in zip file) and Alteryx workflow detailing the question, slightly updated solution/code sample.