If I have an R script:
#! /usr/bin/env Rscript
args <- commandArgs(TRUE)
t <- read.table(args[2], header = TRUE)
print(t$args[1])
q(status = 0)
which I use with the TSV file “example-table.tsv”:
"a" "b"
1 3
2 2
3 1
…using the Bash command: ./example.R a example-table.tsv… (after making the R script executable, of course)
Why does t$args[1] return NULL? How do I get this example to return the proper data.frame column that I specify in the script arguments?
Thanks for you help!
I realize this may or may not be a better question for programming, rather than Cross Validated…?
try:
note that
t$args[1]is parsed as(t$args)[1]->NULL[1]->NULLbecause your data.frame has no ‘args’ column.