'How To Get Rscript To Function For Collaborators
I'm helping in developing a pipeline for researchers and one of the steps require parsing of a large Excel spreadsheet in order to subset and export a file based on some key columns and parameter ranges.
I've written the code and have the repo hosted via GitLab and available for cloning within my organization.
However my collaborators have been unable to get the code to run and I've gone over a session via Teams to see whether they were cloning the repo correctly, had the correct input file and whether they were entering the command and arguments correctly.
Using Rscript the command is running absolutely correctly on my Biolinux terminal however for unknown reasons my collaborators keep getting odd error messages that seem to be related to the terminal and not R:
Error in !colargs: invalid argument type Calls: ... col_spec_standardise-> as.col_spec->my_cols-> Execution halted
Any suggestions on figuring out what exactly is going on?
Edit: Below is the code I'm using
#!/usr/bin/env Rscript
args = commandArgs(trailingOnly = T)
# args = list("allDB_03282022.txt", "ATL", 2018, 1, 12, "SURRG_ATL_2018_JAN_DEC.csv")
# Import magrittr expressions
`%>%` <- magrittr::`%>%`
`%<>%` <- magrittr::`%<>%`
# Define function my_cols
my_cols <- function(..., .default = readr::col_guess()) {
dots <- rlang::enexprs(...)
colargs <- purrr::flatten_chr(unname(
purrr::imap(dots, ~ {
colnames <- rlang::syms(.x)
colnames <- colnames[colnames != rlang::sym("c")]
coltypes <- purrr::rep_along(colnames, .y)
purrr::set_names(coltypes, colnames)
})
))
readr::cols(!!!colargs, .default = .default)
}
surrg_all <- readr::read_tsv(file = args[1], col_names = TRUE, na = "NA",
col_types = my_cols(D = c(TEST_DATE, SPECIMEN_COLLECTION_DATE, DATE_WGSID_ASSIGNED, DATE_RESULT_RELEASED),
# f = c(GC_FACILITY_CODE, SEQUENCING_LAB, GCWGS_DL_FROM_ARLN, SHIPPED_ARLN,
# ARLN_PHL, JURISDICTION_PHL, PATIENT_GENDER, SPECIMEN_TYPE,
# BETALAC_RESULT_CODE, SPECIMEN_QUALITY, YR_COLLECT, MTH_COLLECT)
))
# Change select variable types to factor
surrg_all %<>%
dplyr::mutate(dplyr::across(c(GC_FACILITY_CODE, YR_COLLECT, MTH_COLLECT), as.factor))
# remove rows with NA in any of the variables GC_FACILITY_CODE, YR_COLLECT or MTH_COLLECT
surrg_all %<>% tidyr::drop_na(GC_FACILITY_CODE, YR_COLLECT, MTH_COLLECT)
# Use forcats::fct_collapse() to assign levels to shared GC_FACILITY_CODE factors
surrg_all %<>% dplyr::mutate(GC_FACILITY_CODE2 = forcats::fct_collapse(surrg_all$GC_FACILITY_CODE,
ALB = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^ALB")))),
ANC = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^ANC")))),
ATL = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^ATL")))),
BAL = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^BAL")))),
BHM = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^BHM")))),
BOS = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^BOS")))),
BUF = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^BUF")))),
CAM = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^CAM")))),
CHI = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^CHI")))),
CLE = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^CLE")))),
COL = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^COL")))),
DAL = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^DAL")))),
DEN = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^DEN")))),
GRB = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^GRB")))),
HON = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^HON")))),
IND = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^IND")))),
JAC = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^JAC")))),
KAZ = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^KAZ")))),
KCY = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^KCY")))),
LA = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^LA")))),
LVG = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^LVG")))),
MIA = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^MIA")))),
MIL = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^MIL")))),
MIN = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^MIN")))),
NOR = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^NOR")))),
NYC = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^NYC")))),
ORA = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^ORA")))),
PHI = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^PHI")))),
PHX = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^PHX")))),
PON = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^PON")))),
POR = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^POR")))),
SDG = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^SDG")))),
SEA = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^SEA")))),
SFO = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^SFO")))),
TRP = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^TRP")))),
WDC = as.character(unique(subset(surrg_all$GC_FACILITY_CODE, stringr::str_detect(surrg_all$GC_FACILITY_CODE, "^WDC"))))
), .after = GC_FACILITY_CODE) # %>% View()
# Export output file
surrg_all %>%
dplyr::filter(GC_FACILITY_CODE2 == args[2], YR_COLLECT == args[3], MTH_COLLECT %in% args[[4]]:args[[5]]) %>%
dplyr::select(!GC_FACILITY_CODE2) %>%
readr::write_csv(file = args[[6]] , quote = "none", na = "")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
