load_SL_tibble: load_SL_tibble

Description Usage Arguments Value Examples

View source: R/SL_tbl_load.R

Description

Import a chosen StudentLife table as a tibble. Leave schema and table unspecified to choose interactively via a menu. This function is only intended for use with the studentlife dataset in it's original format, with the original directory structure. See the examples below for the recommended alternative approach to loading tables when the RData format is used.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
load_SL_tibble(
  schema,
  table,
  location = ".",
  time_options = c("interval", "timestamp", "dateonly", "dateless"),
  vars,
  csv_nrows,
  datafolder = "dataset",
  uid_range = getOption("SL_uids")
)

Arguments

schema

A character string. The menu 1 choice. Leave blank to choose interactively.

table

A character string. The menu 2 choice. Leave blank to choose interactively.

location

The path to a copy of the StudentLife dataset.

time_options

A character vector specifying which table types (out of "interval", "timestamp", "dateonly" and "dateless") to include in the menu. This allows you to restrict menu options according to the amount of date-time information present in the data. The default includes all data. Note this parameter only has an effect when used with the interactive menu.

vars

Character vector of variable names to import for all students. Leave blank and this will be chosen interactively if necesssary. If vars contains "timestamp" then effort will be made to convert "timestamp" to appropriate variable name(s) for the target table.

csv_nrows

An integer specifying the number of rows to read per student if the target is a csv. The largest files in StudentLife are csv files, so this allows code testing with less overhead.

datafolder

Specifies the subfolder of location that contains the relevant data. This should normally be left as the default.

uid_range

An integer vector. The range of uids in the StudentLife study.

Value

An object of class SL_tibble is returned. These inherit properties from class tibble and class data.frame. Depending on the date-time information available, the object may also be a timestamp_SL_tibble, interval_SL_tibble or dateonly_SL_tibble (which are all subclasses of SL_tibble).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
## Example that uses RData format to efficiently
## download and load tables, as an alternative
## to using this function.
## Not run: 
d <- tempdir()
download_studentlife(location = d, url = "rdata")

# Choose the schema and table from the list SL_tables:
SL_tables

# Example with activity table from sensing schema
schema <- "sensing"
table <- "activity"
act <- readRDS(paste0(d, "/dataset_rds/", schema, "/", table, ".Rds"))
act

## End(Not run)

## Example that uses the studentlife dataset in
## its original format.

# Use url = "dartmouth" for the full original dataset
d <- tempdir()
download_studentlife(location = d, url = "testdata")

## Not run: 
## With menu
load_SL_tibble(location = d)

## End(Not run)

## Without menu
SL_tables
PAM <- load_SL_tibble(schema = "EMA", table = "PAM", location = d)

## Load less data for testing with less overhead
act <- load_SL_tibble(schema = "sensing", table = "activity",
                     location = d, csv_nrows = 10)

## Not run: 
## Browse all tables with timestamps (non-interval)
load_SL_tibble(location = d, time_options = "timestamp")

## Browse all tables with intervals
load_SL_tibble(location = d, time_options = "interval")

## Browse all dateless tables
load_SL_tibble(location = d, time_options = "dateless")

## End(Not run)

frycast/studentlife documentation built on April 25, 2021, 11:09 a.m.