A Modern and Flexible Data Pipeline for 'SurveyCTO'

A modern and flexible R client for the 'SurveyCTO', a mobile and offline data collection platform, providing a modern and consistent interface for programmatic access to server resources. Built on top of the 'httr2' package, it enables secure and efficient data retrieval and returns analysis-ready data through optional tidying. It includes functions to create, upload, and download server datasets, in addition to fetching form data, files, and submission attachments. Robust authentication and request handling make the package suitable for automated survey monitoring and downstream analysis.


ctoclient: A Modern and Flexible Data Pipeline for 'SurveyCTO' ctoclient logo

R-CMD-check CRAN status cran checks Codecov test coverage minimal R version DOI

ctoclient is a modern, fast, and flexible high-level R client for the SurveyCTO REST API. Built on top of the robust httr2 framework, it provides a consistent and pipe-friendly interface for programmatic access to server resources.

Why use ctoclient?

  • Analysis Ready: Automatically tidies messy API responses into clean data frames.
  • Encrypted Data Support: Seamlessly handle encrypted forms with private keys.
  • Full Resource Coverage: Manage forms, server datasets, attachments, and metadata.
  • Modern Auth: Robust session handling and secure credential management.
  • Extendable: Built on httr2 request objects, allowing for easy customization and extension of API requests.
  • Stata Integration: Built-in tools for generating .do files and templates for legacy pipelines.

Installation

Install the stable version from CRAN:

install.packages("ctoclient")

Or get the development version with the latest features:

# install.packages("pak")
pak::pak("GutUrago/ctoclient")

Quick start

Connect once, then work. Every function picks up the active session on its own, so there is no connection object to pass around.

library(ctoclient)

# Leave the password out and you are prompted for it securely
cto_connect(server = "myorg", username = "[email protected]")

# What is on the server?
cto_form_ids()

# Download and tidy submissions
data <- cto_form_data("baseline_survey")

# Download the photos respondents submitted
cto_form_data_attachment("baseline_survey", fields = ends_with("_img"))

# Label a Stata export, and generate a Word copy of the form for review
cto_form_dofile("baseline_survey", path = "baseline_labels.do")
cto_form_docx("baseline_survey", path = "baseline_review.docx")

cto_form_data() does real work on your behalf: it types numeric, date and datetime fields from the form definition, drops structural rows, splits geopoints into _lat/_long/_alt/_acc, strips URLs from media columns, and fills in the select_multiple binary columns that the export omits when nobody picked an option. Pass tidy = FALSE to get the server's raw export instead.

Documentation

The function reference lists everything the package exports, grouped by task.

Security

Never hard-code passwords in a script. Store them in .Renviron (usethis::edit_r_environ()) and read them with Sys.getenv(), or keep them in your system credential store with the keyring package. See Managing connections for the details.

Contributing

We welcome contributions! If you encounter a bug or have a feature request, please open an issue. Pull requests should include updated tests and documentation.

Disclaimer

This package is an independent, open-source project. It is not affiliated with, endorsed by, or maintained by SurveyCTO or Dobility, Inc. Use it at your own risk, and always ensure you handle survey credentials and participant data securely.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("ctoclient")

0.2.3 by Gutama Girja Urago, 2 days ago


https://guturago.github.io/ctoclient/, https://github.com/guturago/ctoclient/


Report a bug at https://github.com/guturago/ctoclient/issues


Browse source code at https://github.com/cran/ctoclient


Authors: Gutama Girja Urago [aut, cre, cph] (ORCID:


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports checkmate, cli, curl, dplyr, flextable, httr2, jsonlite, officer, purrr, readr, readxl, rlang, stringr, tidyr

Suggests httptest2, knitr, rmarkdown, testthat


See at CRAN