Skip to content

Instantly share code, notes, and snippets.

@SCgeeker
Created June 27, 2019 01:40
Show Gist options
  • Save SCgeeker/403dbfbd2d06a5d25089600f9c688860 to your computer and use it in GitHub Desktop.
Save SCgeeker/403dbfbd2d06a5d25089600f9c688860 to your computer and use it in GitHub Desktop.
Handy code for PSA 002 labratories. Generate Lab seed number and order sequence.
##install.packages("googlesheets")
# Load googlesheets package
library(tidyverse)
library(googlesheets)
library(randomizeR)
# Connect R and my google drive
gs_auth(new_user = TRUE)
# Export the sheet.
gs_title("PSA 002 & 003 OBJECT ORIENTATION & GENDERED PREJUDICE") %>%
gs_read(ws = "Sheet1") %>%
write.csv("LAB_INFO.csv", row.names = FALSE)
# Access LAB ID from downloaded sheet
LABID <- read.csv("LAB_INFO.csv") %>% select(Lab.ID,Planned.N)
# Assign each LAB a seed number
set.seed(20190627)
LAB_SEED <- data.frame(LABID, SEED = runif(dim(LABID)[1],min=101,max=999) %>% floor())
# Select a LAB by Lab ID
ID <- "TWN_001"
# Randomize task order for each LAB
LAB_param <- LAB_SEED %>%
filter(Lab.ID == ID)
# print LAB SEED; Input this number in the first screen.
print(LAB_param$SEED)
# Create the task order sheet
LAB_Order_sheet <- bind_cols(Subj_Num = 1:LAB_param$Planned.N,
Order = crPar(LAB_param$Planned.N,groups = c("1","2")) %>%
genSeq(seed = LAB_param$SEED) %>%
getRandList() %>%
t() )
# Export the sheet
print(LAB_Order_sheet)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment