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

Error: object 'Indicator Name' not found, in for loop pull #76

Open
ghost opened this issue Jul 8, 2019 · 2 comments
Open

Error: object 'Indicator Name' not found, in for loop pull #76

ghost opened this issue Jul 8, 2019 · 2 comments

Comments

@ghost
Copy link

ghost commented Jul 8, 2019

Hi,

I have a script which pulls related indicators for several CCGs in to a list - this was previously working fine however since Friday last week I've been experiencing this error code which happens randomly part way through the for loop.

At whatever indicator I get the error message, I've tried running the internals of the for loop once individually with that indicator and it works fine. There's nothing changed about the code so I'm not sure what's going wrong - any help would be appreciated.

Code:

geog <- c("E38000220", "E38000046", "E38000144", "E38000191", "E38000210", "E38000038", "E38000164", "E38000195", "E38000078", "E38000139", "E38000166", "E38000211", "E38000147", "E38000183", "E38000028", "E38000053", "E38000126", "E38000153", "E38000173", "E38000175"
)

indicators <- c(241, 92588, 90672, 92950, 92951, 92952, 92878, 92879, 90691, 90692, 92882, 92883, 90696, 92886, 92887, 90694, 90702, 91238, 92828, 92830, 92832, 92834, 92836, 92842, 92870, 92874, 93001, 92829, 92831, 92833, 92835, 92837, 92843, 92871, 92875, 93003, 93245, 93246, 93244, 93247, 93248, 93049, 93047, 93051, 90700)

result_list <- vector("list", length = length(indicators))
names(result_list) <- indicators

for (indicator_number in indicators) {
    # load the data once per indicator
    tmpDF <- fingertips_data(IndicatorID = indicator_number, AreaTypeID = c(152, 154, 165))
    # retrieve the rows corresp. to max per geog
    out <- t(vapply(seq_along(geog), function (s) {
        row_geog <- which(.subset2(tmpDF, which(names(tmpDF) == 'AreaCode')) == geog[s])
        row_max <- which.max(.subset2(tmpDF, which(names(tmpDF) == 'TimeperiodSortable'))[row_geog])
        res <- tmpDF[row_geog,c("Timeperiod","Value", "Count", "Denominator")][row_max,]
        res <- c(Timeperiod = res$Timeperiod, Value = res$Value,
                 Count = res$Count, Denominator = res$Denominator)
        if (length(res) == 0) res <- c(Timeperiod = NA_character_, Value = NA_character_,
                                       Count = NA_character_, Denominator = NA_character_)
        return (res)
    }, character(4)))
    # save result for indicator[k]
    result_list[[as.character(indicator_number)]] <- data.frame(indicator = indicator_number, 
                                                                geog,
                                                                Timeperiod = out[,1],
                                                                Value = as.numeric(out[,2]),
                                                                Count = as.numeric(out[,3]),
                                                                Denominator = as.numeric(out[,4]),
                                                                stringsAsFactors = FALSE)
    print(paste0(indicator_number, ": success"))
}
@sebastian-fox
Copy link
Member

Hi @VictorYuNHS - thanks for reporting this. I've been seeing this too a lot recently. There is an issue with the API at the moment. I've reported this to the website developers. I'm afraid I don't know what to recommend to do in the meantime other than keep trying.

I'll get back to you when I have an update.

Thanks again

@sebastian-fox
Copy link
Member

Hi @VictorYuNHS - we're looking into improving our servers. This might take some time.

In the meantime, I've modified the development version package slightly to retry API calls 5 times when they are getting time outs. This should help users in similar situations as you.

To install the development version you can run:

remotes::install_github("rOpenSci/fingertipsR",
                        build_vignettes = TRUE,
                        dependencies = "suggests")

Having said that, I ran your code this morning and it all ran ok without any issues.

If you're happy with this, please could you close this issue. Many thanks

(relevant commit: 8f6a2dc)

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

No branches or pull requests

1 participant