knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(datavyur)
It is important to understand the parts of one or more Datavyu files to understand how to use this R package. The structure is basically organized like so:
For example, you may have several Datavyu files with multiple "columns" in each file, and in each column exists the standard onset
, offset
, and ordinal
fields and their values, along with custom fields that hold their "codes."
|datavyu_file1.opf |- column_name1 | |- cell | |- onset <ts> | |- offset <ts> | |- ordinal <int> | |- custom_code_id1 <code> | |- custom_code_id2 <code> | |- cell | |- onset <ts> | |- offset <ts> | |- ordinal <int> | |- custom_code_id1 <code> | |- custom_code_id2 <code> | |- ... |- column_name2 | |- cell | |- onset <ts> | |- offset <ts> | |- ordinal <int> | |- custom_code_id1 <code> | |- custom_code_id2 <code> | |- ... |datavyu_file2.opf |- column_name1 | |- ... |- column_name2 | |- ... |...
This is a basic example which shows you how to import Datavyu data into R. First, load the package.
# Load the datavyur library to use the functions below library(datavyur)
Next, point to a directory containing .csv
data that has been previously exported using the script datavyu2csv.rb
(see the section "Exporting Datavyu .opf
files" below). This example uses the internal package data directory for demonstration purposes.
ex_data_dir <- datavyur_internal_data()
dv_info <- datavyu_search(folder=ex_data_dir)
The folder ex_data_dir
originally contained r length(unique(dv_info$file))
.opf
files that have been split into r length(unique(dv_info$local))
separate .csv
files, one .csv
file for each Datavyu file (.opf
) and column combination.
Names of .csv
files after using the Ruby script datavyu2csv.rb
:
list.files(ex_data_dir, pattern="\\.csv$")
Names of the original Datavyu .opf
files:
unique(dv_info$file)
Names of the Datavyu columns found inside the set of exported .csv
files:
unique(dv_info$column)
This information can be obtained by using the function datavyu_search
.
datavyu_search(folder=ex_data_dir)
Use the import_datavyu
function to import Datavyu columns into R as separate data.frames
.
Since there are multiple Datavyu columns that need to be imported from ex_data_dir
, set as_list=TRUE
to import a data.frame
for each Datavyu column.
dv_columns <- import_datavyu(folder=ex_data_dir, as_list=TRUE)
You can access each data.frame
like so:
child_data <- dv_columns$childhands
The first few rows are shown below.
knitr::kable(head(child_data))
main_list <- import_datavyu_to_list()
To align data found in the folder ex_data_dir
use the function temporal_align
.
time_aligned1 <- temporal_align(folder=ex_data_dir, fps=30, columns="childhands")
knitr::kable(head(time_aligned1))
ord_aligned1 <- ordinal_align(folder=ex_data_dir, columns="parenthands")
knitr::kable(head(ord_aligned1))
To stack several Datavyu columns' data vertically, use the function vert_merge_datavyu_list
. This will convert all codes to characters so that they're able to exist in a single column.
vert_data <- vert_merge_datavyu_list(main_list)
knitr::kable(rbind(head(vert_data), tail(vert_data)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.