Error when downloading data with R-Studio/Robotoolbox Package

Using an R-Script I have been able to download data from Kobotoolbox for several of my forms, however during the Processing stage for a few of them I get an error.

Error in `abort_table_not_in_dm()`:
! Table `NA` not in `dm` object. Available table names: `main`.
Run `rlang::last_trace()` to see where the error occurred.

The structure of the script is the same. Why would something be referencing a table called NA?

The same process has worked just fine on the majority of other forms made and produces a full set of data I can interact with. Has anyone using this system encountered this error before?

@peat, sharing this post, which should help you solve your issue cc: @dickoa:

The only example of that would be a decimal type column in one form which has a few minus numbers ‘-1’, ‘-2’, ‘-3’ and ‘-0.2’, but I don’t know if that would be a problem?

Some of the other forms which produce this error don’t actually have any data in them yet.

Hi @peat

Thanks for raising this issue. It might be related to a repeat_group, can you share a copy or minimal version of the xlsform. I need to reproduce the error to be able to fix it.

Thanks again

1 Like

Hi @dickoa, thankyou for your assistance with this! Happy to share the XLS form with you, unfortunately as a new user I am unable to upload files to this forum. I have just sent you the file via Wetransfer to the email you have listed on Github. If this isn’t going to work then please let me know how is best to get the file to you.

Thanks again!

1 Like

@peat, you should now be able to share your XLSForm through the community. Refresh your page if you are still not able to upload it.

Thanks, that seems to have worked!

eotb_form.xlsx (25.5 KB)

1 Like

Perfect, and also got it through my email. I’ll take a look, and I’ll come back to you.

2 Likes

@peat

I would love to understand better the project. I used your xlsform and added some data, and it works for me. For some reasons, I can’t reproduce it on my own.

image

I think there’s a repeat group created that we can’t access or something related to that. I’ll continue to see how to reproduce it but you have an idea or something that can help, please don’t hesitate.

1 Like

Hi @dickoa

Thanks for looking at this a while ago! I have come back to the issue as it is still unresolved.

I wanted to check to see if the script I am using to connect RStudio to Kobo is correct. It is what I have been using successfully to connect to my other working forms but wondered if this one needed something different? I noted in your code snippet that you reference ‘kobo_data(uid)’ which is not in my script at all!

This is what I am using -

#install.packages(“robotoolbox”)
library(robotoolbox) # KoboToolbox API
library(dplyr) # data wrangling
library(dm) # data modelling
library(labelled) # extract labels
library(janitor) # clean names
library(stringr) # string manipulation
library(tidyr) # data transformations

kobo_setup(url = “https://kf.kobotoolbox.org”,
token = “xxx”)

l ← kobo_asset_list()
l
form ← kobo_asset(‘xxx’)
dm ← kobo_submissions(form, all_versions = T, progress = T)
dm_draw(dm, rankdir = “RL”)

Hi @peat

kobo_data(uid) and kobo_data(kobo_asset(uid)) will you the same result. kobo_data and kobo_submissions are the same function too (alias).
I think the issue is elsewhere, I added few things on the dev version not specific to this issue, but you can try with the dev version

pak::pkg_install("dickoa/robotoolbox")

You can also try to read the latest version of the form only

...
dm <- kobo_submissions(form, all_versions = FALSE, progress = TRUE)
...
1 Like

Hi @dickoa

Thanks for the suggestions, I have (fingers-crossed), got this working now.

You’d suggested that Repeat sections of the form may be an issue so I removed them and the form worked. They were Repeat image submissions which I haven’t got in any of my other forms so I haven’t used this before.

I added ese back in one at a time and it continued to work. I did make one change though, one of these Repeat image questions was previously inside a group, it is now outside of that group and stands as its own question so perhaps that has made a difference?

Either way, it’s working now so I am happy! Until it breaks again anyway!

1 Like

Unfortunately, I’ve had this come up again.

A different form this time, it was working completely fine this morning, I was connecting and reading data through R Studio just fine, as it has been for the past 6 months. Then I deleted some data manually from the Browser and I have started getting the same error again.

This is becoming a major problem as I have no idea what has changed since this morning to have stopped it working. Other forms still work fine.

I have since created a completely fresh project and re-uploaded the form and have the same error when the processing phase occurs.

EDIT: I have managed to get it to the point where it connects and I can see all the column headings in R-Studio, but as soon as I add any data I get the below error again and cannot connect. I have uploaded different versions of the form that previously worked fine to the same result.

I have shared the full form and error below. I Know we have drawn blanks before on the subject but any help at all would be appreciated.

eotb_form_V9.xlsx (28.5 KB)

Error in abort_table_not_in_dm():
! Table NA not in dm object. Available table names: main.
Run rlang::last_trace() to see where the error occurred.
:heavy_multiplication_x: Processing data [1.2s]

Backtrace:

  1. ├─robotoolbox::kobo_submissions(form, all_versions = T, progress = T)
  2. └─robotoolbox:::kobo_submissions.kobo_asset(…)
  3. └─robotoolbox:::kobo_data_(…)
  4. ├─base::unique(subs[[j]][["_parent_table_name"]])
    
  5. ├─subs[[j]]
    
  6. └─dm:::`[[.dm`(subs, j)
    
  7.   └─dm:::tbl_impl(x, id, quiet = TRUE)
    
  8.     └─dm:::abort_table_not_in_dm(from, src_tbls_impl(dm))
    

So a further thing I have discovered.

I mentioned that I have been able to connect when no data is in the Kobo form and see column headers? Well looking through I have just noticed that there is a column called ‘NA’. This potentially fits in with the error I have been receiving as that refers to ‘NA’.

Capture

I don’t know why this column is being created though. It comes between two questions on my form for no obvious reason.

Whatever it was, this appears to have been the problem.

I removed the neighbouring sections from my form completely and manually re-wrote them from scratch. Despite it being the EXACT same code, the form now works and is not generating the ‘NA’ column.

Why? I have absolutely no idea whatsoever! If anyone can shed any light on the subject I would love to know as I’m now terrified of this happening again!

Hi @peat,

I hope all is good. Happy to take a look at it.
I’ll need to understand better and reproduce it, to work on a fix.

Thank you

1 Like

It does seem to reliably produce the NA column whenever I delete some data from form using the browser version of Kobo. Once I do that I have to rebuild the second half of the form piece by piece to get rid of that column.

Since I realised this I haven’t had the problem come up again (fingers crossed!).

Thank you for looking into this though, I appreciate the attention to something nobody else seems to be having issue with!