Skip to content

Commit

Permalink
changes in text and prettify code remove unnecessary files and imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Patricia Zauchner committed Sep 30, 2024
1 parent 5ad6c05 commit 68c1793
Show file tree
Hide file tree
Showing 46 changed files with 306 additions and 284 deletions.
50 changes: 22 additions & 28 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,43 +1,37 @@
Package: gmoTree
Title: Get and Modify 'oTree' Data
Version: 1.2.0-9003
Date: 2024-09-20
Version: 1.2.0
Date: 2024-09-30
Authors@R:
person("Patricia F.", "Zauchner", , "patricia.zauchner@gmx.at", role = c("aut", "trl", "cre", "cph"),
comment = c(ORCID = "https://orcid.org/0000-0002-5938-1683"))
person(given = "Patricia F.", family = "Zauchner",
role = c("aut", "trl", "cre", "cph"),
email = "patricia.zauchner@gmx.at",
comment = c("https://orcid.org/0000-0002-5938-1683", "University of Bremen"))
Description: Efficiently manage and process data from 'oTree' experiments.
Import 'oTree' data and clean them by using
functions to deal with messy data, dropouts,
and other problematic cases. Create IDs, calculate the time, transfer
functions that handle messy data, dropouts, and other problematic cases.
Create IDs, calculate the time, transfer
variables between app data frames, and delete sensitive information.
You can also check your experimental data before running the
experiment and automatically make a codebook for your oTree code.
Review your experimental data prior to running
the experiment and automatically generate a detailed summary
of the variables used in your 'oTree' code.
Information on 'oTree' is found in Chen, D. L., Schonger, M., &
Wickens, C. (2016) <doi:10.1016/j.jbef.2015.12.001>.
License: GPL (>= 3)
URL: https://zauchnerp.github.io/gmoTree/, https://github.com/ZauchnerP/gmoTree/, https://github.com/ZauchnerP/gmoTree
URL: https://zauchnerp.github.io/gmoTree/,
https://github.com/ZauchnerP/gmoTree/,
https://github.com/ZauchnerP/gmoTree
BugReports: https://github.com/ZauchnerP/gmoTree/issues
Depends:
R (>= 4.4.0)
Imports:
data.table (>= 1.15.4),
dplyr (>= 1.1.4),
knitr (>= 1.47),
openxlsx (>= 4.2.5.2),
pander (>= 0.6.5),
plyr (>= 1.8.9),
rlang (>= 1.1.4),
rlist (>= 0.4.6.2),
rmarkdown (>= 2.27),
stats (>= 4.4.0),
stringr (>= 1.5.1)
Suggests:
testthat (>= 3.2.1),
withr (>= 3.0.0)
VignetteBuilder:
knitr
Depends: R (>= 4.4.0)
Imports: data.table (>= 1.15.4), dplyr (>= 1.1.4), knitr (>= 1.47),
openxlsx (>= 4.2.5.2), pander (>= 0.6.5), plyr (>= 1.8.9),
rlang (>= 1.1.4), rlist (>= 0.4.6.2), rmarkdown (>= 2.27),
stringr (>= 1.5.1)
Suggests: testthat (>= 3.2.1), withr (>= 3.0.0)
VignetteBuilder: knitr
BuildVignettes: true
Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.2
NeedsCompilation: no
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ export(show_dropouts)
import(knitr)
import(pander)
import(rmarkdown)
import(stats)
import(stringr)
import(utils)
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Minor changes in tests.R
* Minor changes in website, new logo

# gmoTree 1.0.1 (available also on CRAN)
# gmoTree 1.0.1

* Minor changes in examples and DESCRIPTION file.
* Changes in functions: NONE
Expand Down
6 changes: 3 additions & 3 deletions R/apptime.R
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ apptime <- function(oTree,
message_vector,
firststageproblemparticipants,
warningparticipants) {
if (nrow(singledurations) > 0) {
if (nrow(singledurations) > 0L) {
output[[appname]][["mean_duration"]] <-
ifelse(rounded,
round(
Expand Down Expand Up @@ -787,7 +787,7 @@ apptime <- function(oTree,

output[[appname]]$first_app_one_page <- firststageproblemparticipants

if (length(warningparticipants) > 0) {
if (length(warningparticipants) > 0L) {
output[[appname]]$warnings <- unique(warningparticipants)
}
} # Else:
Expand All @@ -802,7 +802,7 @@ apptime <- function(oTree,
firststageproblemparticipants,
warningparticipants) {
# Output for all participants or several
if (length(apps) == 1) {
if (length(apps) == 1L) {
return(output_oneapp(
singledurations,
message_vector,
Expand Down
21 changes: 7 additions & 14 deletions R/codebook.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
#' @import knitr
#' @import pander
#' @import rmarkdown
#' @import stats
#' @import stringr
#' @import utils
#' @returns
Expand Down Expand Up @@ -209,7 +208,7 @@ codebook <- function(path = ".",
settings_replace = "global",
user_settings = NULL,
include_cons = TRUE,
preamb = TRUE,
preamb = FALSE,
encoding = "UTF-8",
title = "Codebook",
subtitle = "created with gmoTree",
Expand All @@ -236,7 +235,7 @@ codebook <- function(path = ".",
}

# Check if fsource is valid
if (length(fsource) > 1) {
if (length(fsource) > 1L) {
stop("Please enter only one fsource!")
}

Expand All @@ -250,7 +249,7 @@ codebook <- function(path = ".",
# Others ####
# Check output format
if (!is.character(output) ||
length(output) != 1 ||
length(output) != 1L ||
!(output %in% c("list", "both", "file"))) {
stop("Output should be \"list\", \"both\", or \"file\"!")
}
Expand Down Expand Up @@ -330,11 +329,11 @@ codebook <- function(path = ".",

# Check if app(s) exist(s)
if (!is.null(app)) {
if (length(app) == 1) {
if (!(app %in% basename(dirname(files)))) { # TODO
if (length(app) == 1L) {
if (!(app %in% basename(dirname(files)))) {
stop("App \"", app, "\"is not in oTree code!")
}
} else if (length(app) > 1) {
} else if (length(app) > 1L) {
for (app_i in seq_along(app)) {

if (!(app[app_i] %in% basename(dirname(files)))) {
Expand All @@ -351,7 +350,7 @@ codebook <- function(path = ".",
"odt_document", "rtf_document", "md_document")

if (is.null(output_format) ||
length(output_format) > 1 ||
length(output_format) > 1L ||
!(output_format %in% allowed_formats)) {
stop("Output format should be one of the following: ",
paste0(allowed_formats, collapse = ", "), "!")
Expand Down Expand Up @@ -393,12 +392,6 @@ codebook <- function(path = ".",
stop("Please don't use relative paths in output_dir!")
}

# If dir is combined with a relative output_file path
# if (!is.null(output_file) && grepl("^\\.", x = output_file)) {
# stop("Please don't use relative paths in output_file ",
# "if output_dir is not empty!")
# } # TODO das ist doch quatsch oder?

# If dir is not there
if (!dir.exists(output_dir)) {

Expand Down
2 changes: 1 addition & 1 deletion R/delete_dropouts.R
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ delete_dropouts <- function(oTree,

inconsistent <- readLines(
con = getOption("mypkg.connection"),
n = 1)
n = 1L)
}

# Stop if user requests it
Expand Down
18 changes: 9 additions & 9 deletions R/make_ids.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ make_ids <- function(oTree,

} else if (from_app == "all_apps_wide") {
if (is.null(oTree[[from_app]][[from_var]])) {
stop(paste0("from_var \"",
stop("from_var \"",
from_var,
"\" not found. ",
"Please select another one."))
"Please select another one.")
}
}

Expand Down Expand Up @@ -181,19 +181,19 @@ make_ids <- function(oTree,
}

# Check for NAs in the relevant variables
if (any(is.na(oTree[[from_app]]$participant.code))) {
if (anyNA(oTree[[from_app]]$participant.code)) {
stop("There are NAs in your participant.code variable in your ",
"from_app! Clean your data or assign ",
"participant.code values by hand ",
"before running this function!")
}

if (any(is.na(oTree$Chats$participant_code))) {
if (anyNA(oTree$Chats$participant_code)) {
stop("There are NAs in your participant_code variable in ",
"the oTree$Chats data frame.")
}

if (any(is.na(oTree$Chats$participant__code))) {
if (anyNA(oTree$Chats$participant__code)) {
stop("There are NAs in your participant__code variable in ",
"the oTree$Chats data frame.")
}
Expand Down Expand Up @@ -400,7 +400,7 @@ make_ids <- function(oTree,

if (length(
unique(oTree[[from_app]][, grep("group.id_in_subsession",
colnames(oTree[[from_app]]))])) == 1) {
colnames(oTree[[from_app]]))])) == 1L) {

my_warnings <<- c(my_warnings, paste0(
"The group variable values are constant. ",
Expand Down Expand Up @@ -549,7 +549,7 @@ make_ids <- function(oTree,
} else {
# This part is usually called if session.code is NA
# This does not happen with cleaned data
if (any(is.na(oTree[[from_app]]$session.code))) {
if (anyNA(oTree[[from_app]]$session.code)) {
my_warnings <-
c(my_warnings,
(paste0("At least one of your session.codes in your from_app is ",
Expand Down Expand Up @@ -671,7 +671,7 @@ make_ids <- function(oTree,
!(oTree[[i]]$participant.code %in%
oTree[[from_app]]$participant.code)])

if (length(participants_more) > 0) {
if (length(participants_more) > 0L) {
my_warnings <- c(my_warnings,
paste0("Data frame \"",
names(oTree)[[i]],
Expand Down Expand Up @@ -740,7 +740,7 @@ make_ids <- function(oTree,
j <- j + 1
}
oTree[[i]] <-
oTree[[i]][ , c(c((ncol(oTree[[i]]) - j):ncol(oTree[[i]])),
oTree[[i]][, c(c((ncol(oTree[[i]]) - j):ncol(oTree[[i]])),
c(1L:(ncol(oTree[[i]]) - j - 1L)))
] # Again -1 because otherwise a number is there twice

Expand Down
2 changes: 1 addition & 1 deletion R/messy_chat.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ messy_chat <- function(oTree,
stop(paste(stop_messages, collapse = "\n"))
}

if (info == TRUE && length(warning_messages) > 0L) {
if (info && length(warning_messages) > 0L) {
# This is printed as a warning because other functions catch the message
warning(paste(warning_messages, collapse = "\n"))
}
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ status](https://www.r-pkg.org/badges/version/gmoTree)](https://cran.r-project.or

gmoTree is an R package developed for importing, merging, and
efficiently managing data obtained from running
<a href="https://www.otree.org/" target="_blank">oTree</a> experiments.
<a href="https://www.otree.org/" target="_blank">oTree</a> (Chen et al., 2016) experiments.
It’s particularly valuable when dealing with complex experimental
designs that span multiple sessions and generate a large number of files
that need to be integrated.[^1]
Expand Down Expand Up @@ -89,15 +89,20 @@ apps.

- `pagesec()`: Calculates the time spent on each page.

# Transferring variables between the apps
## Transferring variables between the apps

- `assignv()`: Copies a variable from the all_apps_wide data frame to the data frames
of all other apps.

- `assignv_to_aaw()`: Copies a variable from one of your data frames to the `all_apps_wide` data
frame.

# Before running the experiment
## Before running the experiment

- `show_constant()`: Shows constant variables.
- `codebook()`: Creates a codebook based on the oTree code. See also the vignette <a href="https://zauchnerp.github.io/gmoTree/articles/codebook.html" target="_blank">"gmoTree Codebooks."</a>


# References

Chen, D. L., Schonger, M., & Wickens, C. (2016). oTree—An open-source platform for laboratory, online, and field experiments. Journal of Behavioral and Experimental Finance, 9, 88–97. https://doi.org/10.1016/j.jbef.2015.12.001
Binary file added build/vignette.rds
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 68c1793

Please sign in to comment.