### Example Setup Source: https://sjentsch.github.io/jmvReadWrite/reference/arrange_cols_omv.html Basic setup for defining input and output file paths for the function. ```R nmeInp <- system.file("extdata", "AlbumSales.omv", package = "jmvReadWrite") nmeOut <- tempfile(fileext = ".omv") ``` -------------------------------- ### Example Input Setup Source: https://sjentsch.github.io/jmvReadWrite/reference/combine_cols_omv.html Assigning a sample dataset to a variable for processing. ```R dtaInp <- jmvReadWrite::bfi_sample2 ``` -------------------------------- ### replace_omv Usage Examples Source: https://sjentsch.github.io/jmvReadWrite/reference/replace_omv.html Examples demonstrating how to replace values in a data frame, write the output to a file, and verify the changes. ```R if (FALSE) { # \dontrun{ bfi_sample <- jmvReadWrite::bfi_sample # the gender in the original data file is plural... table(bfi_sample$gender) # and shall be converted to singular rplDF <- jmvReadWrite::replace_omv(dtaInp = bfi_sample, rplLst = list(c("Females", "Female"), c("Males", "Male"))) table(rplDF$gender) # with giving an output file name, the data set is written nmeOut <- tempfile(fileext = ".omv") jmvReadWrite::replace_omv(bfi_sample, fleOut = nmeOut, rplLst = list(c("Females", "Female"), c("Males", "Male"))) file.exists(nmeOut) rplDF <- jmvReadWrite::read_omv(nmeOut) table(rplDF$gender) unlink(nmeOut) # it is sensible to check / search for the original values before running replace_omv jmvReadWrite::search_omv(bfi_sample, 24, whlTrm = TRUE) rplDF <- jmvReadWrite::replace_omv(bfi_sample, rplLst = list(c(24, NA))) table(rplDF$age) } # } ``` -------------------------------- ### Create a jamovi file with metadata using describe_omv Source: https://sjentsch.github.io/jmvReadWrite/reference/describe_omv.html This example demonstrates how to prepare a data frame and a metadata list to generate a .omv file. ```R dtaFrm <- jmvReadWrite::ToothGrowth[, c("len", "supp", "dose")] nmeOut <- tempfile(fileext = ".omv") # the paste's underneath are only for readability (without them, the vignettes are misformatted) lstDsc <- list(description = paste("The response is the length of odontoblasts (cells responsible", "for tooth growth) in 60 guinea pigs. Each animal received one", "of three dose levels of vitamin C (0.5, 1, and 2 mg / day) by", "one of two delivery methods, orange juice or ascorbic acid (a", "form of vitamin C and coded as VC)."), variables = list(len = "Tooth length", supp = "Supplement type (VC or OJ)", dose = "Dose (in milligrams / day"), references = paste("Crampton, E. W. (1947). The growth of the odontoblast of the", "incisor teeth as a criterion of vitamin C intake of the guinea", "pig. The Journal of Nutrition, 33(5), 491-504.", "https://doi.org/10.1093/jn/33.5.491"), license = "") jmvReadWrite::describe_omv(dtaInp = dtaFrm, fleOut = nmeOut, dtaTtl = "ToothGrowth", dtaDsc = lstDsc) ``` -------------------------------- ### Install jmvReadWrite Source: https://sjentsch.github.io/jmvReadWrite/index.html Commands to install the package from CRAN or the development version from GitHub. ```R install.packages("jmvReadWrite") ``` ```R if (!require(devtools)) install.packages("devtools") devtools::install_github("sjentsch/jmvReadWrite") ``` -------------------------------- ### Sort a jamovi data file Source: https://sjentsch.github.io/jmvReadWrite/reference/sort_omv.html Example demonstrating how to sort an existing .omv file by a specific variable and verify the output. ```R nmeInp <- system.file("extdata", "AlbumSales.omv", package = "jmvReadWrite") nmeOut <- tempfile(fileext = ".omv") jmvReadWrite::sort_omv(dtaInp = nmeInp, fleOut = nmeOut, varSrt = "Image") dtaFrm <- jmvReadWrite::read_omv(nmeOut) unlink(nmeOut) cat(dtaFrm$Image) ``` -------------------------------- ### Combine split columns into a single variable Source: https://sjentsch.github.io/jmvReadWrite/reference/combine_cols_omv.html This example shows how to create a subset column, move values, and then use combine_cols_omv to merge them back together. ```R set.seed(1) selRow <- rnorm(nrow(dtaInp)) < 0 dtaInp[selRow, "A1_1"] <- dtaInp[selRow, "A1"] dtaInp[selRow, "A1"] <- NA head(dtaInp[, c("A1", "A1_1")]) dtaOut <- combine_cols_omv(dtaInp, varPrs = list(c("A1", "A1_1"))) dtaInp[, "A1"] dtaOut[, "A1"] all(dtaOut[, "A1"] == jmvReadWrite::bfi_sample2[, "A1"]) ``` -------------------------------- ### Merge multiple datasets into a single jamovi file Source: https://sjentsch.github.io/jmvReadWrite/reference/merge_cols_omv.html This example demonstrates how to prepare three RDS files and merge them into a single .omv file using a common ID column. ```R dtaInp <- jmvReadWrite::bfi_sample2 nmeInp <- paste0(tempfile(), "_", 1:3, ".rds") nmeOut <- tempfile(fileext = ".omv") for (i in seq_along(nmeInp)) { saveRDS(stats::setNames(dtaInp, c("ID", paste0(names(dtaInp)[-1], "_", i))), nmeInp[i]) } # save dtaInp three times (i.e., the length of nmeInp), adding "_" + 1 ... 3 as index # to the data variables (A1 ... O5, gender, age → A1_1, ...) jmvReadWrite::merge_cols_omv(dtaInp = nmeInp, fleOut = nmeOut, varBy = "ID") cat(file.info(nmeOut)$size) #> 16376 # -> 17731 (size may differ on different OSes) dtaOut <- jmvReadWrite::read_omv(nmeOut, sveAtt = FALSE) # read the data set where the three original datasets were added as columns and show # the variable names cat(names(dtaOut)) #> ID A1_1 A2_1 A3_1 A4_1 A5_1 C1_1 C2_1 C3_1 C4_1 C5_1 E1_1 E2_1 E3_1 E4_1 E5_1 N1_1 N2_1 N3_1 N4_1 N5_1 O1_1 O2_1 O3_1 O4_1 O5_1 gender_1 age_1 ID2_1 A1_2 A2_2 A3_2 A4_2 A5_2 C1_2 C2_2 C3_2 C4_2 C5_2 E1_2 E2_2 E3_2 E4_2 E5_2 N1_2 N2_2 N3_2 N4_2 N5_2 O1_2 O2_2 O3_2 O4_2 O5_2 gender_2 age_2 ID2_2 A1_3 A2_3 A3_3 A4_3 A5_3 C1_3 C2_3 C3_3 C4_3 C5_3 E1_3 E2_3 E3_3 E4_3 E5_3 N1_3 N2_3 N3_3 N4_3 N5_3 O1_3 O2_3 O3_3 O4_3 O5_3 gender_3 age_3 ID2_3 cat(names(dtaInp)) #> ID A1 A2 A3 A4 A5 C1 C2 C3 C4 C5 E1 E2 E3 E4 E5 N1 N2 N3 N4 N5 O1 O2 O3 O4 O5 gender age ID2 ``` -------------------------------- ### Transforming data from long to wide format Source: https://sjentsch.github.io/jmvReadWrite/reference/long2wide_omv.html This example demonstrates generating a test dataframe, saving it as an RDS file, and converting it to a wide-format jamovi file using long2wide_omv. ```R # generate a test dataframe with 100 (imaginary) participants / units of # observation (ID), 8 measurement (measure) of one variable (X) dtaInp <- data.frame(ID = rep(as.character(seq(1, 100)), each = 8), measure = rep(seq(1, 8), times = 100), X = runif(800, -10, 10)) cat(str(dtaInp)) #> 'data.frame': 800 obs. of 3 variables: #> $ ID : chr "1" "1" "1" "1" ... #> $ measure: int 1 2 3 4 5 6 7 8 1 2 ... #> $ X : num -6.758 -0.492 -9.961 -1.171 -4.781 ... # the output should look like this # 'data.frame': 800 obs. of 3 variables: # $ ID : chr "1" "1" "1" "1" ... # $ measure: int 1 2 3 4 5 6 7 8 1 2 ... # $ X : num ... # this data set is stored as (temporary) RDS-file and later processed by long2wide nmeInp <- tempfile(fileext = ".rds") nmeOut <- tempfile(fileext = ".omv") saveRDS(dtaInp, nmeInp) jmvReadWrite::long2wide_omv(dtaInp = nmeInp, fleOut = nmeOut, varTgt = "X", varID = "ID", varTme = "measure") ``` -------------------------------- ### Extract and Execute Analysis Syntax Source: https://sjentsch.github.io/jmvReadWrite/index.html Retrieves and executes analysis syntax stored as attributes within a jamovi data object. Requires the jmv package to be installed for execution. ```R if (length(attr(data, "syntax")) >= 2) { attr(data, "syntax") # if the "jmv"-package is installed, we can run the analyses in "syntax" if ("jmv" %in% rownames(installed.packages())) { eval(parse(text = attr(data, "syntax")[[1]])) eval(parse(text = paste0("result = ", attr(data, "syntax")[[2]]))) names(result) # -> "main" "assump" "contrasts" "postHoc" "emm" # (the names of the five output tables) } } ``` -------------------------------- ### Read .omv files and run analysis Source: https://sjentsch.github.io/jmvReadWrite/index.html Demonstrates reading a jamovi data file and executing an ANOVA using the jmv package. ```R fleOMV <- system.file("extdata", "ToothGrowth.omv", package = "jmvReadWrite") data <- jmvReadWrite::read_omv(fleOMV) # if the "jmv"-package is installed, we can run a test analysis with the data if ("jmv" %in% rownames(installed.packages())) { jmv::ANOVA( formula = len ~ supp + dose + supp:dose, data = data, effectSize = c("omega"), modelTest = TRUE, homo = TRUE, norm = TRUE) } ``` -------------------------------- ### Define output file path Source: https://sjentsch.github.io/jmvReadWrite/reference/write_omv.html Create a temporary file path with the .omv extension for use with write_omv. ```R nmeOut <- tempfile(fileext = ".omv") ``` -------------------------------- ### Read .omv file with syntax extraction Source: https://sjentsch.github.io/jmvReadWrite/reference/read_omv.html Imports a jamovi file and attempts to extract the associated analysis syntax. Requires jmvcore and RProtoBuf packages. ```R if (FALSE) { # \dontrun{ data <- jmvReadWrite::read_omv(fleInp = nmeInp, getSyn = TRUE) } # } ``` -------------------------------- ### Merge multiple jamovi files by rows Source: https://sjentsch.github.io/jmvReadWrite/reference/merge_rows_omv.html Demonstrates creating sample RDS files and merging them into a single .omv file using merge_rows_omv. ```R dtaInp <- jmvReadWrite::bfi_sample2 nmeInp <- paste0(tempfile(), "_", 1:3, ".rds") nmeOut <- tempfile(fileext = ".omv") for (i in seq_along(nmeInp)) saveRDS(dtaInp[-i - 1], nmeInp[i]) # save dtaInp three times (i.e., the length of nmeInp), removing one data columns in # each data set (for demonstration purposes, A1 in the first, A2 in the second, ...) jmvReadWrite::merge_rows_omv(dtaInp = nmeInp, fleOut = nmeOut, colInd = TRUE) cat(file.info(nmeOut)$size) #> 10936 # -> 10767 (size may differ on different OSes) dtaOut <- jmvReadWrite::read_omv(nmeOut, sveAtt = FALSE) unlink(nmeOut) # read the data set where the three original datasets were added as rows and show # the variable names cat(names(dtaInp)) #> ID A1 A2 A3 A4 A5 C1 C2 C3 C4 C5 E1 E2 E3 E4 E5 N1 N2 N3 N4 N5 O1 O2 O3 O4 O5 gender age ID2 cat(names(dtaOut)) #> fleInd ID A2 A3 A4 A5 C1 C2 C3 C4 C5 E1 E2 E3 E4 E5 N1 N2 N3 N4 N5 O1 O2 O3 O4 O5 gender age ID2 A1 # compared to the input data set, we have the same variable names; fleInd (switched ``` -------------------------------- ### Verify OMV File Creation Source: https://sjentsch.github.io/jmvReadWrite/reference/aggregate_omv.html Check the existence and size of the generated OMV file. ```R cat(list.files(dirname(nmeOut), basename(nmeOut))) cat(file.info(nmeOut)$size) ``` -------------------------------- ### Inspect variable labels in OMV file Source: https://sjentsch.github.io/jmvReadWrite/reference/label_vars_omv.html Loads a sample OMV file and checks the current variable description attributes. ```R nmeInp <- system.file("extdata", "bfi_sample.omv", package = "jmvReadWrite") dtaInp <- jmvReadWrite::read_omv(nmeInp)[1:28] nmeOut <- tempfile(fileext = ".omv") # in the original file, the variable labels – attr(*, "jmv-desc") - are empty lapply(dtaInp, attr, "jmv-desc") ``` -------------------------------- ### Extracting Analysis Syntax from .omv Files Source: https://sjentsch.github.io/jmvReadWrite/articles/jmvReadWrite.html Use getSyn = TRUE to extract syntax from jamovi analyses stored within an .omv file. Syntax is accessible via the 'syntax' attribute of the returned data object. ```R fleOMV <- system.file("extdata", "ToothGrowth.omv", package = "jmvReadWrite") data <- jmvReadWrite::read_omv(fleOMV, getSyn = TRUE) # shows the syntax of the analyses from the .omv-file # please note that syntax extraction may not work on all systems # if the syntax couldn't be extracted, an empty list (length = 0) is returned, # otherwise, the syntax of the analyses from the .omv-file is shown and # the commands of the first and the second analysis are run, with the # output of the second analysis assigned to the variable result if (length(attr(data, "syntax")) >= 2) { attr(data, "syntax") # if the "jmv"-package is installed, we can run the analyses in "syntax" if ("jmv" %in% rownames(installed.packages())) { eval(parse(text = attr(data, "syntax")[[1]])) eval(parse(text = paste0("result = ", attr(data, "syntax")[[2]]))) names(result) # -> "main" "assump" "contrasts" "postHoc" "emm" # (the names of the five output tables) } } ``` -------------------------------- ### convert_to_omv(fleInp, fleOut, varSrt, usePkg, selSet, ...) Source: https://sjentsch.github.io/jmvReadWrite/reference/convert_to_omv.html Converts a specified input data file into a jamovi .omv file. This function supports various file formats and allows for sorting and package selection for reading specific file types. ```APIDOC ## convert_to_omv ### Description Converts data files (CSV, R, and other statistics packages) into .omv-files for the statistical spreadsheet 'jamovi'. ### Usage convert_to_omv(fleInp = "", fleOut = "", varSrt = c(), usePkg = c("foreign", "haven"), selSet = "", ...) ### Arguments - **fleInp** (string) - Name (including path) of the input data file. - **fleOut** (string) - Name (including path) of the output .omv file. If empty, the input extension is replaced with .omv. - **varSrt** (vector) - Variable(s) used to sort the data frame. - **usePkg** (vector) - Package to use for reading SPSS, Stata, and SAS files ("foreign" or "haven"). - **selSet** (string) - Name of the data set to select from the workspace (applies to .RData files). - **...** (dots) - Additional arguments passed to internal reading and writing functions. ### Value Returns NULL. ``` -------------------------------- ### Verify File Creation and Cleanup Source: https://sjentsch.github.io/jmvReadWrite/reference/write_omv.html Checks for the existence of the written file on disk and removes it after verification. ```R print(list.files(dirname(nmeOut), basename(nmeOut))) print(file.info(nmeOut)$size) unlink(nmeOut) ``` -------------------------------- ### Extract syntax from .omv files Source: https://sjentsch.github.io/jmvReadWrite/index.html Retrieves analysis syntax stored within an .omv file by setting the getSyn parameter to TRUE. ```R fleOMV <- system.file("extdata", "ToothGrowth.omv", package = "jmvReadWrite") data <- jmvReadWrite::read_omv(fleOMV, getSyn = TRUE) ``` -------------------------------- ### Generate jamovi file description with formatting Source: https://sjentsch.github.io/jmvReadWrite/reference/describe_omv.html Uses HTML tags to apply various styles like bold, italics, lists, and alignment to the jamovi file description. ```R # don't include the unlink, if you copy the code and want to look at the resulting output file unlink(nmeOut) # the code underneath should cover all formatting options jamovi is able to use (paste0 is only # for readability) chrDsc <- paste0("
Trial - all formattings:
bold
",
"bold, italics
italics
underlined",
"strikethrough
C2H5OH
R2",
"
background colour: red",
"
foreground color: red",
"
centered
", "right
justify justify justify justify justify ", "justify justify justify justify justify justify justify justify justify justify ", "justify justify justify justify justify justify justify justify justify justify", "
",
"
", "indented once
indented twice
indented once
Formula: ", "e=mc^2
Preformatted
normal again