
Link two sensors OR one sensor and an external data frame using an mpathsenser database
Source:R/linking.R
link_db.RdThis function is deprecated in favour of link(). It used to be a wrapper around link() but
extracts data in the database for you.
Usage
link_db(
db,
sensor_one,
sensor_two = NULL,
external = NULL,
external_time = "time",
offset_before = 0,
offset_after = 0,
add_before = FALSE,
add_after = FALSE,
participant_id = NULL,
start_date = NULL,
end_date = NULL,
reverse = FALSE,
ignore_large = FALSE
)Arguments
- db
A database connection to an m-Path Sense database.
- sensor_one
The name of a primary sensor. See sensors for a list of available sensors.
- sensor_two
The name of a secondary sensor. See sensors for a list of available sensors. Cannot be used together with
external.- external
Optionally, specify an external data frame. Cannot be used at the same time as a second sensor. This data frame must have a column called
time.- external_time
The name of the column containing the timestamps in
external.- offset_before
The time before each measurement in
xthat denotes the period in whichyis matched. Must be convertible to a period bylubridate::as.period().- offset_after
The time after each measurement in
xthat denotes the period in whichyis matched. Must be convertible to a period bylubridate::as.period().- add_before
Logical value. Do you want to add the last measurement before the start of each interval?
- add_after
Logical value. Do you want to add the first measurement after the end of each interval?
- participant_id
A character string identifying a single participant. Use
get_participantsto retrieve all participants from the database. Leave empty to get data for all participants.- start_date
Optional search window specifying date where to begin search. Must be convertible to date using as.Date. Use first_date to find the date of the first entry for a participant.
- end_date
Optional search window specifying date where to end search. Must be convertible to date using as.Date. Use last_date to find the date of the last entry for a participant.
- reverse
Switch
sensor_onewith eithersensor_twoorexternal? Particularly useful in combination withexternal.- ignore_large
Safety override to prevent long wait times. Set to
TRUEto do this function on lots of data.
Value
A tibble with the data of sensor_one with a new column data with the matched data of
either sensor_two or external according to offset_before or offset_after. The other way
around when reverse = TRUE.
Examples
if (FALSE) { # \dontrun{
# Open a database
db <- open_db("path/to/db")
# Link two sensors
link_db(db, "accelerometer", "gyroscope", offset_before = 300, offset_after = 300)
# Link a sensor with an external data frame
link_db(db, "accelerometer",
external = my_external_data,
external_time = "time", offset_before = 300, offset_after = 300
)
} # }