Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

R版Getopt::Longを作ってみた

4.597 Aufrufe

Veröffentlicht am

Tsukuba.R #9のLTです

Veröffentlicht in: Business, Technologie
  • Als Erste(r) kommentieren

R版Getopt::Longを作ってみた

  1. 1. R Getopt::Long Tsukuba.R #9 (2011/11/12) @a_bicky
  2. 2. parseArgs <- function() { argv <- commandArgs(trailingOnly = TRUE) argv <- strsplit(argv, "=") argv <- sapply(argv, function(arg) { ret <- ifelse(is.na(arg[2]), 1, arg[2]) names(ret) <- arg[1] return(ret) }) # show usage # Not use existsFunction because loading methods packagetakes about 60% of the startup time if ("help" %in% names(argv)) { tryCatch(usage(), error = function(e) cat("No usage forthis scriptn")) quit() } # check arguments # Not use existsFunction because loading methods packagetakes about 60% of the startup time try(checkArgs(argv), silent = TRUE) return(argv)}
  3. 3. orz
  4. 4. Getopt::Long
  5. 5. Perl parseruse Getopt::Long;my $data = "file.dat";my $length = 24;my $verbose;$result = GetOptions ("length=i" => $length, # numeric "file=s" => $data, # string "verbose" => $verbose); # flag http://search.cpan.org/~jv/Getopt-Long-2.38/lib/Getopt/Long.pmgetopt_long_sample.pluse Getopt::Long;GetOptions(save_path=s => $save_path);print "$save_pathn";$ perl getopt_long_sample.pl --save_path=hogehoge
  6. 6.
  7. 7. http://d.hatena.ne.jp/a_bicky/20111020/1319061009
  8. 8. http://d.hatena.ne.jp/a_bicky/20111020/1319061009
  9. 9. http://d.hatena.ne.jp/a_bicky/20111020/1319061009
  10. 10. getopt_long_sample.Rsource("GetoptLong.R")GetOptions(save.path=s = save.path)print(save.path)GetOptions(var1=s = var1, # var2=i = var2, # var3=f = var3, # var4 = var4, # var5=s@ = var5, # var6=i% = var6 #)
  11. 11. getopt_long_sample.Rsource("GetoptLong.R")GetOptions(save.path=s = save.path)print(save.path)use Getopt::Long;GetOptions(save_path=s => $save_path);print "$save_pathn";
  12. 12. getopt_long_sample.Rsource("GetoptLong.R")GetOptions(save.path=s = save.path)print(save.path)use Getopt::Long;GetOptions(save_path=s => $save_path);print "$save_pathn";
  13. 13. getopt_long_sample.Rsource("GetoptLong.R")GetOptions(save.path=s = save.path)print(save.path)$ RScript getopt_long_sample.R --save.path=hoge[1] "hoge"
  14. 14. getopt_long_sample.Rsource("GetoptLong.R")GetOptions(save.path=s = save.path)print(save.path)
  15. 15. getopt_long_sample.Rsource("GetoptLong.R")GetOptions(save.path=s = save.path)print(save.path)
  16. 16. Rgetopt_long_sample.Rsource("GetoptLong.R")GetOptions(save.path=s = save.path)print(save.path) save.path# parent.framevar.names <- as.character(match.call()[-1])assign(var, ret[[var]], envir = parent.frame())
  17. 17. Rgetopt_long_sample.Rsource("GetoptLong.R")GetOptions(save.path=s = save.path)print(save.path) save.path# parent.framevar.names <- as.character(match.call()[-1])assign(var, ret[[var]], envir = parent.frame()) http://user.ecc.u-tokyo.ac.jp/~s105503/p02.html

×