<div dir="ltr">Hi Ezra,<div><br></div><div>Thanks for your help. It sounds like implementing this feature will be hard if I reply on making a custom geo. I'm going to try what you suggest at the end - making the geo with the wildcard, and then removingwhat I don't need before returning it to the client.</div>
<div><br></div><div>Ari</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Apr 14, 2014 at 12:47 PM, Ezra Haber Glenn <span dir="ltr"><<a href="mailto:eglenn@mit.edu" target="_blank">eglenn@mit.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Ari:<br>
<br>
Good question. Here are some thoughts on how to approach it:<br>
<br>
Your idea of creating something with geo.make(zip.code= "*"), and then<br>
modifying, if a great idea, but unfortunately it won't work: the<br>
geo.set that you create with a wildcard is pretty dumb -- it just<br>
contain the wildcard, not all the geographies that it matches to.<br>
<br>
Nonetheless, it's a good start, and can be used to get those<br>
geographies through a simple acs.fetch. Try this:<br>
<br>
> my.geos=geo.make(zip.code="*")<br>
<br>
# the actual table number doesn't really matter here<br>
> some.data=acs.fetch(geography=my.geos, table.number="B01003")<br>
<br>
Now we have an acs.object, called some.data, that *does* include all<br>
the geographic info we need. We can view it with<br>
<br>
# careful -- the whole thing is really long;<br>
# let's just look at the first few rows<br>
> head(geography(some.data))<br>
NAME zipcodetabulationarea<br>
1 ZCTA5 01001 01001<br>
2 ZCTA5 01002 01002<br>
3 ZCTA5 01003 01003<br>
4 ZCTA5 01005 01005<br>
5 ZCTA5 01007 01007<br>
6 ZCTA5 01008 01008<br>
<br>
We can capture the "zipcodetabulationarea" values and use some subset<br>
of them to make a new geo.make:<br>
<br>
> sample.zips=geo.make(zip.code=sample(geography(some.data)$zipcodetabulationarea, 100))<br>
<br>
Unfortunately, if you try to make a geo.set with *all* of them, you<br>
get that same error you encountered -- it has to do with the way the<br>
function uses nested recursive loops, which may be less-than-ideal in<br>
theory, but in practice is fine. (I think the upper limit may be<br>
around 700 or 800 items.) To get around this, you could create your<br>
geo.set in multiple pieces, and then combine them with "geo.set.a +<br>
geo.set.b" of something similar.<br>
<br>
But all that said, I'd warn you that the acs.fetch command is *very*<br>
slow with very large geo.sets -- each one needs to be individually<br>
fetched, and then the results assembled. (This is one reason why the<br>
limit of geo.set size at creation is not really a big problem from my<br>
point of view.) Far better is to just use the wildcard and then<br>
*remove* the rows that you don't want (i.e., select and remove the<br>
ones for Alaska and Hawaii, in this case). Would that work?<br>
<br>
--Ezra<br>
<div><div class="h5"><br>
At Sun, 13 Apr 2014 13:57:32 -0400, arilamstein wrote:<br>
><br>
> I am trying to use geo.make to create a geography of all zip codes /<br>
> zctas in the continental US. This is slightly challenging because the<br>
> documentation to geo.make says that if you specify the zip.code<br>
> parameter then no other geographies can be selected.<br>
><br>
> My solution is to use the zipcode package to create a list of all<br>
> zipcodes in the continental us, and then pass that to geo.make.<br>
> However, this creates an error:<br>
><br>
> library(maps) library(zipcode) data(zipcode)<br>
><br>
> states_continental = setdiff(state.abb, c("AK", "HI"))<br>
> states_continental = c(states_continental, "DC") zips =<br>
> zipcode[zipcode$state %in% states_continental, "zip"]<br>
><br>
> geo = geo.make(zip.code=zips) Error: evaluation nested too deeply:<br>
> infinite recursion / options(expressions=)? Error during wrapup:<br>
> evaluation nested too deeply: infinite recursion /<br>
> options(expressions=)?<br>
><br>
> I tried to step thru the geo.make code but was not sure how it worked.<br>
> I suspect the error is that the zipcode package includes valid zips<br>
> that are not zctas (e.g. zip codes that refer to post offices), and<br>
> that might cause a problem. But I am wondering if there is a bug in<br>
> the acs code, or if there is a better way to get the result I am<br>
> looking for.<br>
><br>
> As a workaround, is there an easy way to remove elements from the<br>
> result of geo.make(zip.code= "*")? The resulting object is an S4<br>
> object, which I don't have experience with. If the result were a<br>
> data.frame I could just use subsetting against the zips variable I<br>
> have above. But I am not sure how to do the equivalent operation with<br>
> the resulting S4 object.<br>
><br>
> Thanks.<br>
><br>
> Ari<br>
><br>
><br>
<br>
</div></div>--<br>
Ezra Haber Glenn, AICP<br>
Department of Urban Studies and Planning<br>
Massachusetts Institute of Technology<br>
77 Massachusetts Ave., Room 7-337<br>
Cambridge, MA 02139<br>
<a href="mailto:eglenn@mit.edu">eglenn@mit.edu</a><br>
<a href="http://dusp.mit.edu/faculty/ezra-glenn" target="_blank">http://dusp.mit.edu/faculty/ezra-glenn</a> | <a href="http://eglenn.scripts.mit.edu/citystate/" target="_blank">http://eglenn.scripts.mit.edu/citystate/</a><br>
<a href="tel:617.253.2024" value="+16172532024">617.253.2024</a> (w)<br>
<a href="tel:617.721.7131" value="+16177217131">617.721.7131</a> (c)<br>
</blockquote></div><br></div>