| cto_connect | R Documentation |
cto_connect() authenticates against a SurveyCTO server, verifies credentials,
and handles cookies.
cto_set_connection() manually sets or restores an existing session object.
cto_is_connected() checks if an active session currently exists in the
internal environment.
cto_connect(server, username, password = NULL, cookies = TRUE)
cto_set_connection(session)
cto_is_connected()
server |
String. The subdomain of your SurveyCTO server.
For example, if the full URL is |
username |
String. The username or email address associated with the account. |
password |
String. The user password. If left |
cookies |
Logical. If |
session |
A |
By default, this package operates statefully by preserving cookies
if the connection is established with the cookies = TRUE argument.
Upon successful authentication, the request object (.session) is assigned to an internal
package environment (.ctoclient_env). Therefore, you do not need to pass a request
object to other functions in this package; they will automatically use the
active session. If you are working with multiple servers, please use cto_set_connection()
to switch the server connection.
It is highly recommended to avoid hard-coding passwords in your scripts.
Interactive Session: Pass the password securely via console input (leave it NULL) or
keychain management tools.
Automation/Scripts: Store your credentials in your .Renviron file
(e.g., SCTO_PASSWORD) and retrieve them with Sys.getenv().
cto_connect(): The session object (invisibly).
cto_set_connection(): NULL (invisibly), called for its side effect of setting the session.
cto_is_connected(): A logical TRUE or FALSE.
httr2::req_auth_basic(), usethis::edit_r_environ()
## Not run:
# 1. Standard authentication
cto_connect("my-org", "user@org.com", Sys.getenv("SCTO_PASSWORD"))
# 2. Check if connected
cto_is_connected()
# 3. Recommended for interactive use
con <- cto_connect("my-org", "user@org.com")
# 4. Restore and existing connection
cto_set_connection(con)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.