Package 'psyinfr'

Title: R functions as an infrastructure for psychological research
Description: psyinfr provides R functions that serve as the infrastructure for psychological research.
Authors: Yoshihiko Kunisato
Maintainer: Yoshihiko Kunisato <[email protected]>
License: MIT + file LICENSE
Version: 0.6.8
Built: 2026-10-08 17:36:42 UTC
Source: https://github.com/ykunisato/psyinfr

Help Index


Add jpaQmd

Description

Add jpaQmd

Usage

add_jpaQmd()

Examples

# add_jpaQmd()

Add paperQmd

Description

Add paperQmd

Usage

add_paperQmd()

Examples

# add_paperQmd()

Print a summary of the object returned by readJatos()

Description

Print a summary of the object returned by readJatos()

Usage

## S3 method for class 'jatos_data'
print(x, ...)

Arguments

x

object of class jatos_data

...

ignored


Read JATOS/jsPsych results and tidy them for analysis in R

Description

Reads a JATOS results file (the text file exported from JATOS, in which each line holds the jsPsych data of one component result) collected with cbat4r::jatosify()-style tasks, and reshapes it into analysis-ready data frames.

Three representations are produced:

  • trials: one row per jsPsych trial. All scalar trial fields (rt, trial_type, trial_index, time_elapsed, ...) become columns; nested fields (e.g. question_order) are collapsed with sep, and deeper structures are kept as JSON text.

  • long: one row per response item (participant x task x trial x item). response objects such as ⁠{"mood_1":1,"mood_2":0}⁠ are unnested into item/value pairs, with a numeric copy in value_num.

  • wide: one row per participant, one column per response item, which is the format usually wanted for statistical analysis.

Besides the line-delimited text export, a whole-file JSON array and the JATOS "JSON with metadata" export are also accepted; in the latter case the surrounding JATOS metadata (worker id, study result id, ...) is carried along in columns prefixed with jatos_.

Usage

readJatos(
  file,
  format = c("all", "trials", "long", "wide"),
  id_col = "workerID",
  task_col = "taskName",
  response_col = "response",
  item_cols = character(),
  index_col = NULL,
  extra_cols = character(),
  prefix = c("auto", "always", "never"),
  sep = "|",
  drop_cols = character(),
  encoding = "UTF-8"
)

Arguments

file

Path to a JATOS results file (e.g. "jatos_results_data_20260809054431.txt").

format

One of "all" (default, returns a list of the three data frames), "trials", "long" or "wide" (returns that data frame only).

id_col

Name of the trial field identifying a participant. Default "workerID". If absent, JATOS metadata or the result number is used.

task_col

Name of the trial field identifying a task/component. Default "taskName". If absent, the result number is used.

response_col

Name of the trial field holding the response. Default "response".

item_cols

Character vector of further trial fields to treat as response items, in addition to response_col. Useful for tasks that store their answers in custom fields, e.g. item_cols = c("aspect_text", "selected_adjectives"). Each field becomes an item named after the field.

index_col

Name of a trial field that numbers repeated items (e.g. "aspect_number"). When given, long gets an index column and the wide columns are suffixed with it (aspect_text_1, aspect_text_2, ...). If an indexed item occurs more than once for a participant, the last value is kept (it reflects corrections made by going back).

extra_cols

Character vector of trial columns to carry into wide (one value per participant, the first non-missing one). For instance extra_cols = "id" picks up a completion code stored in the trial.

prefix

How to name the columns of wide: "auto" (default) prefixes the task name only when an item name is ambiguous (used by more than one task, or named like response_col), "always" always prefixes, "never" never does.

sep

Separator used when collapsing a vector-valued field into one string. Default "|".

drop_cols

Trial columns to drop from trials; nothing is dropped by default. Set e.g. drop_cols = "stimulus" to discard long HTML strings.

encoding

Encoding of file. Default "UTF-8".

Value

A list of data frames (trials, long, wide) of class jatos_data, or a single data frame if format is not "all".

Examples

# d <- readJatos("jatos_results_data_20260809054431.txt")
# head(d$wide)
# readJatos("jatos_results_data_20260809054431.txt",
#           format = "wide", extra_cols = "id")
# # a task storing answers in custom fields, one set per aspect
# readJatos("jatos_results_data_20261008071223.txt",
#           item_cols = c("aspect_text", "selected_adjectives"),
#           index_col = "aspect_number",
#           extra_cols = c("id", "completion_type"))

render function for Japanese e-labnotebook in PDF

Description

render function for Japanese e-labnotebook in PDF

Usage

render_elnjp_pdf(Rmd_file)

Arguments

Rmd_file

file name of R Markdown file


Render a Quarto Manuscripts project into all of its formats

Description

Runs ⁠quarto render⁠ in the manuscript project, which produces the website (⁠_manuscript/index.html⁠) and the PDF (⁠_manuscript/paper.pdf⁠).

The Render button of RStudio runs ⁠quarto preview⁠, and a preview renders only the first format of the project (the website), leaving the PDF to be built when its download link is clicked. Use this function when the PDF should be built every time.

When the render succeeds, ⁠_manuscript/index.html⁠ is opened in the browser.

Usage

render_manuscript(project_dir = ".", preview = FALSE, open = TRUE)

Arguments

project_dir

Directory of the manuscript project (the folder holding ⁠_quarto.yml⁠). Default ".".

preview

If TRUE, ⁠quarto preview --render all⁠ is run instead, so that all formats are rendered and the preview server is started. Default FALSE.

open

If TRUE (default), ⁠_manuscript/index.html⁠ is opened in the browser after a successful render. Ignored when preview = TRUE, because the preview server opens a browser by itself.

Value

The exit status of the quarto command, invisibly.

Examples

# render_manuscript()
# render_manuscript("manuscript")

start research with new Japanese e-labnotebook

Description

start research with new Japanese e-labnotebook

Usage

researchIn(rc = TRUE)

Arguments

rc

If you are using Research Compendium of senshuRmd, you can create a e-labnotebook file in the "labnote" directory from the current directory. In that case, please set rc to TURE.

Examples

# researchIn()

upload Japanese e-labnotebook to GitHub

Description

upload Japanese e-labnotebook to GitHub

Usage

researchOut(rc = TRUE)

Arguments

rc

If you are using Research Compendium of senshuRmd, you can create a e-labnotebook file in the "labnote" directory from the current directory. In that case, please set rc to TURE.

Examples

# researchOut()

run high load computing and psuh to GitHub

Description

run high load computing and psuh to GitHub

Usage

runHighLoad(r_file)

Arguments

r_file

set r file to run

Examples

# runHighLoad(r_file)

run r files using parallel

Description

run r files using parallel

Usage

runParallelR(r_files)

Arguments

r_files

set vector of r files


R Markdown output formats Template for thesis at Department of Psychology, Senshu University

Description

R Markdown output formats Template for thesis at Department of Psychology, Senshu University

Usage

senshu_thesis(Rmd_file, Bib_file)

Arguments

Rmd_file

file name of R Markdown file

Bib_file

file name of Bib file


Set up a Quarto Manuscripts project with the senshuQmd template

Description

Creates a Quarto manuscript project (project: type: manuscript) whose article is paper.qmd taken from the senshuQmd template (https://github.com/ykunisato/senshuQmd), together with two notebooks, notebooks/Analysis_01.qmd and notebooks/Data_collection.qmd.

The layout created is:

<project>/
  _quarto.yml
  paper.qmd            article (senshuQmd template)
  bibliography.bib
  figures/
  _extensions/senshu/  senshu-pdf format
  notebooks/
    Analysis_01.qmd
    Data_collection.qmd
  data/
    jatos_results_data_demo.txt

Data_collection.qmd holds an example of building an online survey with cbat4r (set_ic(), set_qnr(), set_cc(), jatosify()) in an R chunk, and Analysis_01.qmd an analysis skeleton that reads the demo data in ⁠data/⁠ with readJatos(), so that the project renders as it is.

Usage

set_manuscript(
  project_name = "manuscript",
  output_dir = ".",
  add_root_dir = TRUE,
  overwrite = FALSE,
  open = rstudioapi::isAvailable(),
  branch = "main"
)

Arguments

project_name

Name of the manuscript project. Default "manuscript". Used as the folder name when add_root_dir = TRUE.

output_dir

Where the project is created. Default ".".

add_root_dir

If TRUE (default), a project_name folder is created inside output_dir and the files are placed there. If FALSE, the files are placed directly in output_dir.

overwrite

If TRUE, existing files are overwritten. Default FALSE, which stops when paper.qmd or ⁠_quarto.yml⁠ already exists.

open

If TRUE (default in RStudio), paper.qmd is opened.

branch

Branch of the senshuQmd repository to download. Default "main".

Value

The path of the created project, invisibly.

Examples

# set_manuscript()
# set_manuscript("paper2026", output_dir = "paper")

Research Compendium of Department of Psychology, Senshu University

Description

Research Compendium of Department of Psychology, Senshu University

Usage

set_rc()

Examples

# set_rc()

run high load computing and psuh to GitHub

Description

run high load computing and psuh to GitHub

Usage

setGitSlack(
  git_name,
  git_email,
  slack_token = "FALSE",
  slack_channel = "#general"
)

Arguments

git_name

set user name of GitHub

git_email

set e-mail of GitHub

slack_token

set slack API token

slack_channel

set channel name of slack

Examples

# setGitSlack(user_name_github, email_github, slack_token, slack_channel, slack_username)

upload Japanese e-labnotebook to OSF

Description

upload Japanese e-labnotebook to OSF

Usage

up2osf(eln_osf = TRUE, rc_osf = TRUE)

Arguments

eln_osf

URL of pdf directory in OSF

rc_osf

If you are using Research Compendium of senshuRmd, you can create a e-labnotebook file in the "labnote" directory from the current directory. In that case, please set rc to TURE.