-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetRestingStateOK
executable file
·53 lines (41 loc) · 1.92 KB
/
getRestingStateOK
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/Rscript
# Load libraries required to download from REDCap and install custom packages.
# This loop installs missing pacakges.
for (package in c("REDCapR", "devtools"))
{
if (!require(package, character.only = TRUE))
{
install.packages(package)
library(package, character.only = TRUE)
}
}
# Install the custom UdallR library. You may have to change the path, depending
## on where you downloaded UdallR to.
install("~/UdallR", quiet = TRUE)
library(UdallR, quietly = TRUE, warn.conflicts = FALSE)
today <- gsub("[^0-9]", "", Sys.Date())
outfile <- paste0("closest-visits/closestVisits-", today, ".csv")
# It isn't secure to upload access tokens to GitHub, so store your access token
## in a file like this so R can read it.
rc.token <- readChar("~/UdallR/access-token.txt", nchars = 32)
# Read the data from the REDCap API. "stringsAsFactors" stops R from treating
## important strings as factors (which when written to file, are written as the
## underlying numeric representation.
dat <- as.data.frame(redcap_read(redcap_uri = "https://redcap.iths.org/api/",
token = rc.token),
stringsAsFactors = FALSE)
# Test the UdallR cleaning function
# The visit variable doesn't do much right now.
cdat <- udallCleanREDCapDataWide(dat, visit = 1)
on.rest.ok <- as.logical(cdat$on_analyze_rest_fmri)
off.rest.ok <- as.logical(cdat$off_analyze_rest_fmri)
if (sum(is.na(on.rest.ok)) > 0)
message(paste(sum(is.na(on.rest.ok)), "subjects have NA on rest status."))
if (sum(is.na(off.rest.ok)) > 0)
message(paste(sum(is.na(on.rest.ok)), "subjects have NA off rest status."))
on.rest.subjs <- cdat$idnum[sapply(on.rest.ok, isTRUE)]
off.rest.subjs <- cdat$idnum[sapply(off.rest.ok, isTRUE)]
write.csv(file = "on-rest-OK.txt", on.rest.subjs, quote = FALSE,
row.names = FALSE)
write.csv(file = "off-rest-OK.txt", off.rest.subjs, quote = FALSE,
row.names = FALSE)