Skip to content

Instantly share code, notes, and snippets.

@ChristinaLK
Last active February 10, 2022 22:39
Show Gist options
  • Save ChristinaLK/a672cdd5dc0c0664557befb4df69d98e to your computer and use it in GitHub Desktop.
Save ChristinaLK/a672cdd5dc0c0664557befb4df69d98e to your computer and use it in GitHub Desktop.
using command line arguments
## use:
## python args.py 1 hello True
import sys
values = sys.argv
print(values)
# scriptname is ALWAYS the first item in the list
jobnumber = values[1]
print(jobnumber)
# if you want to use jobnumber as a NUMBER, not a STRING
# jobnumber = int(values[1])
outfile = 'results'+ jobnumber + '.csv'
print(outfile)
## use:
## Rscript args.R 1 hello TRUE
values <- commandArgs(trailingOnly=TRUE)
print(values)
jobnumber <- values[1]
print(jobnumber)
# if you want to use jobnumber as a NUMBER, not a STRING
# jobnumber <- as.numeric(values[1])
outfile <- paste0('results',jobnumber,'.csv')
print(outfile)
@orchid00
Copy link

orchid00 commented Oct 4, 2018

tiny typo in args.R
as.numeric
has an extra a

also nice to add a space after a comma,

@ChristinaLK
Copy link
Author

You are right! Thank you. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment