
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.
ctoclient?httr2 request
objects, allowing for easy customization and extension of API
requests..do files and templates for legacy pipelines.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")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 = "admin@example.com")
# 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.
The function reference lists everything the package exports, grouped by task.
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.
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.
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.