|
json_dir is a list of JSON lists mapping lat/long route points between locations using CloudMade's API. post_url is the URL of the HTTP request for (n in json_dir) { i = i + 1 if (typeof(json_dir[[i]]) != "NULL") { if (i == 1) { dat_add <- ldply(json_dir[[i]], function(x) t(data.frame(x)), .progress = "text") names(dat_add) <- c("lat", "lon") json_path <- list(dat_add) } else { dat_add <- ldply(json_dir[[i]], function(x) t(data.frame(x)), .progress = "text") names(dat_add) <- c("lat", "lon") json_path <- c(json_path, list(dat_add)) } p = p + geom_path(aes(lon, lat), data = json_path[[i]]) } print(paste("Processed ", i, " of ", as.character(length(json_dir)), " in route set.", sep = "")) } This runs until i = 101 and then errors out with, "Error in json_path[[i]] : subscript out of bounds" typeof(json_dir[[101]]) = "list", so it's not that the first if-block is somehow resetting json_path in an errant fashion. Do lists have a default, built-in limit on no. of elements? Each element I'm passing contains hundreds or thousands of lat/long pairs, so it's also possible I'm hitting some upper bound on per-object memory, if that exists, but Googling around leads me to think that's not the case. I think I've fucked something up in my logic, but I'm not sure what. |
|
On 2012-04-04 14:25, z2.0 wrote:
> > > json_dir is a list of JSON lists mapping lat/long route points between > locations using CloudMade's API. > post_url is the URL of the HTTP request > > for (n in json_dir) { > i = i + 1 > if (typeof(json_dir[[i]]) != "NULL") { > if (i == 1) { > dat_add<- ldply(json_dir[[i]], function(x) > t(data.frame(x)), .progress = "text") > names(dat_add)<- c("lat", "lon") > json_path<- list(dat_add) > } else { > dat_add<- ldply(json_dir[[i]], function(x) > t(data.frame(x)), .progress = "text") > names(dat_add)<- c("lat", "lon") > json_path<- c(json_path, list(dat_add)) > } > > p = p + geom_path(aes(lon, lat), data = json_path[[i]]) > } > print(paste("Processed ", i, " of ", as.character(length(json_dir)), > " in route set.", sep = "")) > } > > This runs until i = 101 and then errors out with, > "Error in json_path[[i]] : subscript out of bounds" > > typeof(json_dir[[101]]) = "list", so it's not that the first if-block is > somehow resetting json_path in an errant fashion. > > Do lists have a default, built-in limit on no. of elements? Each element I'm > passing contains hundreds or thousands of lat/long pairs, so it's also > possible I'm hitting some upper bound on per-object memory, if that exists, > but Googling around leads me to think that's not the case. > I'm guessing that your problem is with the for() statement; you probably want to replace json_dir by a sequence, e.g. for(n in seq_along(json_dir)) {.... Example: L <- list(1,2,3,14) for( i in L) cat( i, L[[i]], "\n" ) for( i in seq_along(L)) cat( i, L[[i]], "\n" ) > I think I've fucked something up in my logic, but I'm not sure what. Hmm, this list is generally more polite. Peter Ehlers > > > -- > View this message in context: http://r.789695.n4.nabble.com/Subscript-Error-tp4533219p4533219.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
|
You should have the following statement as part of your startup for R:
options(error=utils::recover) When an error occurs, you will be at the stack frame where is happens and you can examine the values of the variables that you are using and this should help a lot in tracking down your problem. You can see what the value of 'i' and then look at what the structure of the object you are accessing. We would need the same information to help answer the question you are asking. There is not enough information to say what is happening. Doing the debugging above would be the minimum data that would be need to see what the problem is. If it says you got an indexing error, then you were trying to access something outside the object. On Wed, Apr 4, 2012 at 10:11 PM, Peter Ehlers <[hidden email]> wrote: > On 2012-04-04 14:25, z2.0 wrote: >> >> >> >> json_dir is a list of JSON lists mapping lat/long route points between >> locations using CloudMade's API. >> post_url is the URL of the HTTP request >> >> for (n in json_dir) { >> i = i + 1 >> if (typeof(json_dir[[i]]) != "NULL") { >> if (i == 1) { >> dat_add<- ldply(json_dir[[i]], function(x) >> t(data.frame(x)), .progress = "text") >> names(dat_add)<- c("lat", "lon") >> json_path<- list(dat_add) >> } else { >> dat_add<- ldply(json_dir[[i]], function(x) >> t(data.frame(x)), .progress = "text") >> names(dat_add)<- c("lat", "lon") >> json_path<- c(json_path, list(dat_add)) >> } >> >> p = p + geom_path(aes(lon, lat), data = json_path[[i]]) >> } >> print(paste("Processed ", i, " of ", >> as.character(length(json_dir)), >> " in route set.", sep = "")) >> } >> >> This runs until i = 101 and then errors out with, >> "Error in json_path[[i]] : subscript out of bounds" >> >> typeof(json_dir[[101]]) = "list", so it's not that the first if-block is >> somehow resetting json_path in an errant fashion. >> >> Do lists have a default, built-in limit on no. of elements? Each element >> I'm >> passing contains hundreds or thousands of lat/long pairs, so it's also >> possible I'm hitting some upper bound on per-object memory, if that >> exists, >> but Googling around leads me to think that's not the case. >> > > I'm guessing that your problem is with the for() statement; you > probably want to replace json_dir by a sequence, e.g. > > for(n in seq_along(json_dir)) {.... > > Example: > > L <- list(1,2,3,14) > for( i in L) cat( i, L[[i]], "\n" ) > for( i in seq_along(L)) cat( i, L[[i]], "\n" ) > >> I think I've fucked something up in my logic, but I'm not sure what. > > > Hmm, this list is generally more polite. > > Peter Ehlers > >> >> >> -- >> View this message in context: >> http://r.789695.n4.nabble.com/Subscript-Error-tp4533219p4533219.html >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> [hidden email] mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
|
Thanks to you both. Calling recover (an option hitherto unknown to me) helped me identify the problem.
For the record, the error occurred in the geom_path() line, not the list concatenation, as I had previously thought. It was a logic problem: when typeof == NULL the function jumped, but i remained incrementing, forcing geom_path to call data from a list element that didn't exist. Thanks again. |
| Powered by Nabble | Edit this page |
