ropensci / ruODK

ruODK: An R Client for the ODK Central API
https://docs.ropensci.org/ruODK/
GNU General Public License v3.0
42 stars 13 forks source link

Update computational efficiency of form_schema_ext.R #106

Closed mtyszler closed 3 years ago

mtyszler commented 3 years ago

While testing form_schema_ext() with a large form, it was taking about 3 min to run this function.

After close inspection I realized that the chunks:

        translations <- all_translations[
          xml2::xml_attr(all_translations, "id") == id
        ]

and

            choice_translations <- all_translations[xml2::xml_attr(
              all_translations, "id"
            ) == id_choice]

Are computationally inefficient due to the unnecessary repetition of xml2::xml_attr(all_translations, "id"). By adding this once at the top and using the resulting object to select specific rows, I reduced computational time by 90%.

Function was taking 3 minutes and it takes now 20 seconds.

Nothing else changes structurally

florianm commented 3 years ago

Thanks for the PR! I've merged the PR and released v0.9.4.

mtyszler commented 3 years ago

Thanks for the PR! I've merged the PR and released v0.9.4.

Thank you, @florianm