Last active
February 10, 2022 22:39
-
-
Save ChristinaLK/a672cdd5dc0c0664557befb4df69d98e to your computer and use it in GitHub Desktop.
using command line arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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) |
You are right! Thank you. :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tiny typo in args.R
as.numeric
has an extra a
also nice to add a space after a comma,