Skip to contents

sb_get_event() exports data from a Smartabase event form using the Smartabase API. It requires the user to input a valid Smartabase event form name, date range, url and credentials.

For more details see the help vignette: vignette("exporting-data")

Usage

sb_get_event(
  form,
  date_range,
  url,
  username,
  password,
  ...,
  filter = sb_get_event_filter(),
  option = sb_get_event_option(),
  time_range = c("12:00 am", "11:59 pm")
)

Arguments

form

Name of Smartabase event form

date_range

Character vector of length two containing valid start_date end_date (dd/mm/YYYY) character values

url

Smartabase url e.g. "example.smartabase.com/site"

username

Smartabase username

password

Smartabase password

...

These dots are for future extensions and must be empty

filter

More filters accessible via sb_get_event_filter() object

option

More options accessible via sb_get_event_option() object

time_range

Vector of length two containing a valid start_time and and end_time (h:mm am/pm) character values. Defaults to c("12:00 am", "11:59 pm).

Value

A tibble containing Smartabase event data

date_range

sb_get_event() returns events that occur between a start date and an end date. We must supply these dates via the date_range argument which accepts a vector of length two. The first element is the start date and the second element is the end date. The dates must be character types represented in "dd/mm/YYYY" format.

Alternatively you can use the sb_date_range() function to generate the date range dynamically. See sb_date_range() for more details.

filter

There are also a range extra filters than can be supplied to the filter argument, including user filters, data filters and filters for getting the most recent events. In order to reduce argument clutter in sb_get_event(), all optional filters must be generated by the sb_get_event_filter() function.

time_range

As well as requiring a date range from which to export events, sb_get_event() also optionally allows specification of a valid time range. Similar to date_range, time_range is a length 2 character vector. The first element is the start time and the second element is the end time. The times must be character types represented in "h:mm am/pm" format. Defaults to c("12:00 am", "11:59 pm").

option

There are also a range of extra options than can be supplied to the option argument, including options for downloading attachments and suppressing messages to the console, among others. In order to reduce argument clutter in sb_get_event(), all options must be generated by the sb_get_event_option() function.

See also

sb_get_profile() for profile data. sb_get_user() for user data. sb_sync_event() to synchronise with an event form.

Other export functions: sb_get_profile(), sb_get_user(), sb_sync_event()

Examples

if (FALSE) { # \dontrun{
# Get one week of wellness data from 'example.smartabase.com/site':
sb_get_event(
  form = "Daily Wellness",
  date_range = c("15/04/2023", "22/04/2023"),
  url = "example.smartabase.com/site",
  username = "example.user",
  password = "example_password"
)

# Now retrieve data for the last 7 days using [sb_date_range()],
# then, using [sb_get_event_filter()], filter for users in the Smartabase
# group "example_group" and only return values where "example_field" is
# greater than 1. Also download any attachments if they're available using
# [sb_get_event_option()].
sb_get_event(
  form = "Daily Wellness",
  date_range = sb_date_range("7", "days"),
  url = "example.smartabase.com/site",
  username = "example.user",
  password = "example_password",
  filter = sb_get_event_filter(
    user_key = "group",
    user_value = "example_group",
    data_key = "example_field",
    data_value = 1,
    data_condition = "greater_than"
  ),
  option = sb_get_event_option(
    download_attachment = TRUE
  )
)
} # }