Sort data (using one or more variables) in .omv-files for the statistical spreadsheet 'jamovi' (https://www.jamovi.org)

sort_omv(
fleInp = c(),
fleOut = "",
varSrt = c(),
usePkg = c("foreign", "haven"),
selSet = "",
...
)

## Arguments

fleInp

Name (including the path, if required) of the data file to be read ("FILENAME.ext"; default: ""); can be any supported file type, see Details below

fleOut

Name (including the path, if required) of the data file to be written ("FILENAME.omv"; default: ""); if empty, the extension of fleInp is replaced with "_sorted(file extension -> .omv)"

varSrt

Variable(s) that are used to sort the data frame (see Details; default: c())

usePkg

Name of the package: "foreign" or "haven" that shall be used to read SPSS, Stata and SAS files; "foreign" is the default (it comes with base R), but "haven" is newer and more comprehensive

selSet

Name of the data set that is to be selected from the workspace (only applies when reading .RData-files)

...

Additional arguments passed on to methods; see Details below

## Details

varSrt can be either a character or a character vector (with one or more variables respectively). The sorting order for a particular variable can be inverted with preceding the variable name with "-". Please note that this doesn't make sense and hence throws a warning for certain variable types (e.g., factors). The ellipsis-parameter can be used to submit arguments / parameters to the functions that are used for reading the data. These are: read_omv (for jamovi-files), read.table (for CSV / TSV files; using similar defaults as read.csv for CSV and read.delim for TSV which both are based upon read.table but with adjusted defaults for the respective file types), readRDS (for rds-files), read_sav (needs R-package "haven") or read.spss (needs R-package "foreign") for SPSS-files, read_dta ("haven") / read.dta ("foreign") for Stata-files, read_sas ("haven") for SAS-data-files, and read_xpt ("haven") / read.xport ("foreign") for SAS-transport-files. If you would like to use "haven", it may be needed to install it manually (i.e., install.packages("haven", dep = TRUE)).

## Examples

if (FALSE) {
fleOMV <- system.file("extdata", "AlbumSales.omv", package = "jmvReadWrite");
fleTmp <- paste0(tempfile(), ".omv");
sort_omv(fleInp = fleOMV, fleOut = fleTmp, varSrt = "Image");
cat(dtaFrm$Image); # shows that the variable "Image" is sorted in ascending order cat(is.unsorted(dtaFrm$Image));
# is.unsorted (which checks for whether the variable is NOT sorted) returns FALSE
sort_omv(fleInp = fleOMV, fleOut = fleTmp, varSrt = "-Image");
# variables can also be sorted in descending order by preceding them with "-"
cat(dtaFrm$Image); # shows that the variable "Image" is now sorted in descending order cat(is.unsorted(dtaFrm$Image));