asitav-sen / KoboconnectR

Download data from Kobotoolbox to R
https://asitav-sen.github.io/KoboconnectR/
GNU General Public License v3.0
13 stars 2 forks source link

kobotools_api error retrieving ID #17

Open rkopper-wv opened 1 year ago

rkopper-wv commented 1 year ago

Hello,

I was wondering if anyone encountered the following issue. When running the kobotools_api function to retrieve the list of assets IDs, I am receiving this error: Downloading: 260 kB Error in parsed$results[[i]] : subscript out of bounds

I tried the kobotools_api function with another account that has less data (surveys and submissions) and it worked. I am thinking that perhaps my kobo account has too much data on it for the function to handle. Before I delete some archived data, I was wondering if others have encountered this issue and found some solutions. Or if deleting is the only solution, how much would I need to delete??

I am using: kobotools_api(url="kobo.humanitarianresponse.info", simplified=T, uname="username", pwd=pw)

username is actually replaced with my username*

If I set simplified to F then I can actually download the asset IDs but it comes in the form of a large list (4 elements)

Thanks

asitav-sen commented 1 year ago

Hi @rkopper-wv , Apologies for the delay. Could you resolve the issue?

rkopper-wv commented 1 year ago

No, I used the alternate method of getting a simplified list then manually going into retrieve asset IDs that are embedded in the large list of elements.

asitav-sen commented 1 year ago

Is it possible to include the method in the code? What was the root cause of the issue?

rkopper-wv commented 1 year ago

I just tried it again and this was the error Downloading: 240 kB Error in parsed$results[[i]] : subscript out of bounds

I believe the issue stems from having so many assets as I tried the process with another kobo account, and it worked as usual.

My work around was:

# Check for ids from the list of assets 
id <- kobotools_api(url="kobo.humanitarianresponse.info", simplified=F, uname="username", pwd=pw)

# this results in a large list so i then work to track down and extract asset IDs

id[["results"]]-> cutd

ids <- lapply(1:length(cutd), function(i) {
  cutd[[i]][["uid"]] %>% 
    data.frame()
}) %>% 
  bind_rows()

names(ids) <- "uid"
ids$lst <- seq_along(ids[,1])

snames <- lapply(1:length(cutd), function(i) {
  cutd[[i]][["name"]] %>% 
    data.frame()
}) %>% 
  bind_rows()

names(snames) <- "name"
snames$lst <- seq_along(snames[,1])

df_list <- list(ids,snames)

#merge all data frames in list
df_list <- Reduce(function(x, y) merge(x, y, all=TRUE), df_list)
df_list2 <- df_list
##find  surveys from df

sixmon <- df_list2 %>%
  filter(str_detect(name, "insert text"))

sixmonc <- sixmon %>%
  filter(str_detect(name, "insert text"))
asitav-sen commented 1 year ago

Thanks