SlideShare a Scribd company logo
R   Getopt::Long
               Tsukuba.R #9 (2011/11/12)
                               @a_bicky
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
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' package
takes about 60% of the startup time
    if ("help" %in% names(argv)) {
        tryCatch(usage(), error = function(e) cat("No usage for
this scriptn"))
        quit()
    }

    # check arguments
    # Not use 'existsFunction' because loading 'methods' package
takes about 60% of the startup time
    try(checkArgs(argv), silent = TRUE)

    return(argv)
}
orz
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
Getopt::Long
Perl                                 parser
use 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.pm

getopt_long_sample.pl

use Getopt::Long;
GetOptions('save_path=s' => $save_path);
print "$save_pathn";


$ perl getopt_long_sample.pl --save_path=hoge
hoge
R版Getopt::Longを作ってみた
…
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
http://d.hatena.ne.jp/a_bicky/20111020/1319061009
http://d.hatena.ne.jp/a_bicky/20111020/1319061009
http://d.hatena.ne.jp/a_bicky/20111020/1319061009
R版Getopt::Longを作ってみた
getopt_long_sample.R

source("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    #
)
getopt_long_sample.R

source("GetoptLong.R")
GetOptions('save.path=s' = save.path)
print(save.path)




use Getopt::Long;
GetOptions('save_path=s' => $save_path);
print "$save_pathn";
getopt_long_sample.R

source("GetoptLong.R")
GetOptions('save.path=s' = save.path)
print(save.path)




use Getopt::Long;
GetOptions('save_path=s' => $save_path);
print "$save_pathn";
R版Getopt::Longを作ってみた
getopt_long_sample.R

source("GetoptLong.R")
GetOptions('save.path=s' = save.path)
print(save.path)




$ RScript getopt_long_sample.R --save.path=hoge
[1] "hoge"
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
getopt_long_sample.R

source("GetoptLong.R")
GetOptions('save.path=s' = save.path)
print(save.path)
getopt_long_sample.R

source("GetoptLong.R")
GetOptions('save.path=s' = save.path)
print(save.path)
R版Getopt::Longを作ってみた
R
getopt_long_sample.R

source("GetoptLong.R")
GetOptions('save.path=s' = save.path)
print(save.path)                                  save.path




# parent.frame
var.names <- as.character(match.call()[-1])




assign(var, ret[[var]], envir = parent.frame())
R
getopt_long_sample.R

source("GetoptLong.R")
GetOptions('save.path=s' = save.path)
print(save.path)                                  save.path




# parent.frame
var.names <- as.character(match.call()[-1])




assign(var, ret[[var]], envir = parent.frame())
             http://user.ecc.u-tokyo.ac.jp/~s105503/p02.html
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた

More Related Content

PDF
KubeCon EU 2016: Custom Volume Plugins
PDF
Perl Bag of Tricks - Baltimore Perl mongers
PPT
vfsStream - a better approach for file system dependent tests
PDF
Parsing JSON with a single regex
ODP
vfsStream - effective filesystem mocking
PDF
The Magic Of Tie
PDF
6 things about perl 6
PDF
Utility Modules That You Should Know About
KubeCon EU 2016: Custom Volume Plugins
Perl Bag of Tricks - Baltimore Perl mongers
vfsStream - a better approach for file system dependent tests
Parsing JSON with a single regex
vfsStream - effective filesystem mocking
The Magic Of Tie
6 things about perl 6
Utility Modules That You Should Know About

What's hot (19)

PDF
Perl 5.28 new features
PDF
File Space Usage Information and EMail Report - Shell Script
PDF
Shell Script to Extract IP Address, MAC Address Information
PDF
Bash Script Disk Space Utilization Report and EMail
PDF
Perl 6 by example
PDF
JIP Pipeline System Introduction
KEY
GettingStartedWithPHP
PDF
Hypers and Gathers and Takes! Oh my!
PPT
Hands on Hadoop
PDF
Unix cheatsheet
PDF
Metadata-driven Testing
KEY
PDF
The most exciting features of PHP 7.1
PDF
Perl v5.26 Features (AmsterdamX.pm)
PPTX
Process monitoring in UNIX shell scripting
TXT
Assignment6
PPTX
8. Move in Laravel
PPTX
Cis 216 – shell scripting
PDF
Dumping Perl 6 (AmsterdamX.pm)
Perl 5.28 new features
File Space Usage Information and EMail Report - Shell Script
Shell Script to Extract IP Address, MAC Address Information
Bash Script Disk Space Utilization Report and EMail
Perl 6 by example
JIP Pipeline System Introduction
GettingStartedWithPHP
Hypers and Gathers and Takes! Oh my!
Hands on Hadoop
Unix cheatsheet
Metadata-driven Testing
The most exciting features of PHP 7.1
Perl v5.26 Features (AmsterdamX.pm)
Process monitoring in UNIX shell scripting
Assignment6
8. Move in Laravel
Cis 216 – shell scripting
Dumping Perl 6 (AmsterdamX.pm)
Ad

Viewers also liked (12)

PDF
Rデータフレーム自由自在
ODP
R言語で統計分類基本
PDF
Rによる分類木 入門
PPTX
Fluentd,mongo db,rでお手軽ログ解析環境
PPTX
Tokyo r50 beginner_2
PDF
Collaborativefilteringwith r
PDF
R3.0.0 is relased
PDF
Rでコンジョイント分析
PPTX
Tokyo r30 beginner
PDF
「plyrパッケージで君も前処理スタ☆」改め「plyrパッケージ徹底入門」
PDF
クックパッド特売情報 における自然言語処理 〜固有表現抽出を利用した検索システム〜
PDF
R-3.0.0でGLM
Rデータフレーム自由自在
R言語で統計分類基本
Rによる分類木 入門
Fluentd,mongo db,rでお手軽ログ解析環境
Tokyo r50 beginner_2
Collaborativefilteringwith r
R3.0.0 is relased
Rでコンジョイント分析
Tokyo r30 beginner
「plyrパッケージで君も前処理スタ☆」改め「plyrパッケージ徹底入門」
クックパッド特売情報 における自然言語処理 〜固有表現抽出を利用した検索システム〜
R-3.0.0でGLM
Ad

Similar to R版Getopt::Longを作ってみた (20)

ODP
Introduction to Perl
PDF
20 modules i haven't yet talked about
PPT
You Can Do It! Start Using Perl to Handle Your Voyager Needs
ODP
Introduction to Perl - Day 1
PDF
Modern Getopt for Command Line Processing in Perl
PPT
Perl Presentation
PDF
I, For One, Welcome Our New Perl6 Overlords
PPTX
Groovy
PPT
Bioinformatica 10-11-2011-p6-bioperl
PPTX
Php functions
KEY
Good Evils In Perl (Yapc Asia)
PDF
BSDM with BASH: Command Interpolation
KEY
DPC 2012 : PHP in the Dark Workshop
KEY
Achieving Parsing Sanity In Erlang
KEY
Hidden treasures of Ruby
PDF
Perl6 in-production
PDF
Bag of tricks
ODP
Aura Project for PHP
ODP
KEY
Evolving Tests
Introduction to Perl
20 modules i haven't yet talked about
You Can Do It! Start Using Perl to Handle Your Voyager Needs
Introduction to Perl - Day 1
Modern Getopt for Command Line Processing in Perl
Perl Presentation
I, For One, Welcome Our New Perl6 Overlords
Groovy
Bioinformatica 10-11-2011-p6-bioperl
Php functions
Good Evils In Perl (Yapc Asia)
BSDM with BASH: Command Interpolation
DPC 2012 : PHP in the Dark Workshop
Achieving Parsing Sanity In Erlang
Hidden treasures of Ruby
Perl6 in-production
Bag of tricks
Aura Project for PHP
Evolving Tests

More from Takeshi Arabiki (15)

PDF
開発の心得
PDF
Introduction to Japanese Morphological Analysis
PDF
R による文書分類入門
PDF
Rのデータ構造とメモリ管理
PDF
HTML5 Canvas で学ぶアフィン変換
PDF
Introduction to Favmemo for Immature Engineers
PDF
Rのスコープとフレームと環境と
PDF
twitteRで快適Rライフ!
PDF
RではじめるTwitter解析
PDF
HMM, MEMM, CRF メモ
PDF
文字列カーネルによる辞書なしツイート分類 〜文字列カーネル入門〜
PDF
Rデバッグあれこれ
PDF
はじめてのまっぷりでゅ〜す
PDF
TwitterのデータをRであれこれ
PDF
Twitterのデータを取得する準備
開発の心得
Introduction to Japanese Morphological Analysis
R による文書分類入門
Rのデータ構造とメモリ管理
HTML5 Canvas で学ぶアフィン変換
Introduction to Favmemo for Immature Engineers
Rのスコープとフレームと環境と
twitteRで快適Rライフ!
RではじめるTwitter解析
HMM, MEMM, CRF メモ
文字列カーネルによる辞書なしツイート分類 〜文字列カーネル入門〜
Rデバッグあれこれ
はじめてのまっぷりでゅ〜す
TwitterのデータをRであれこれ
Twitterのデータを取得する準備

Recently uploaded (20)

PPTX
Probability Distribution, binomial distribution, poisson distribution
PDF
Reconciliation AND MEMORANDUM RECONCILATION
PDF
Stem Cell Market Report | Trends, Growth & Forecast 2025-2034
PDF
Lecture 3 - Risk Management and Compliance.pdf
DOCX
unit 1 COST ACCOUNTING AND COST SHEET
PPTX
job Avenue by vinith.pptxvnbvnvnvbnvbnbmnbmbh
PDF
The FMS General Management Prep-Book 2025.pdf
PPTX
Dragon_Fruit_Cultivation_in Nepal ppt.pptx
PDF
Hindu Circuler Economy - Model (Concept)
DOCX
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
PPT
Data mining for business intelligence ch04 sharda
PPTX
ICG2025_ICG 6th steering committee 30-8-24.pptx
PDF
COST SHEET- Tender and Quotation unit 2.pdf
PPTX
5 Stages of group development guide.pptx
PDF
Nidhal Samdaie CV - International Business Consultant
PDF
Dr. Enrique Segura Ense Group - A Self-Made Entrepreneur And Executive
PDF
kom-180-proposal-for-a-directive-amending-directive-2014-45-eu-and-directive-...
PDF
Traveri Digital Marketing Seminar 2025 by Corey and Jessica Perlman
PDF
Katrina Stoneking: Shaking Up the Alcohol Beverage Industry
PDF
Types of control:Qualitative vs Quantitative
Probability Distribution, binomial distribution, poisson distribution
Reconciliation AND MEMORANDUM RECONCILATION
Stem Cell Market Report | Trends, Growth & Forecast 2025-2034
Lecture 3 - Risk Management and Compliance.pdf
unit 1 COST ACCOUNTING AND COST SHEET
job Avenue by vinith.pptxvnbvnvnvbnvbnbmnbmbh
The FMS General Management Prep-Book 2025.pdf
Dragon_Fruit_Cultivation_in Nepal ppt.pptx
Hindu Circuler Economy - Model (Concept)
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
Data mining for business intelligence ch04 sharda
ICG2025_ICG 6th steering committee 30-8-24.pptx
COST SHEET- Tender and Quotation unit 2.pdf
5 Stages of group development guide.pptx
Nidhal Samdaie CV - International Business Consultant
Dr. Enrique Segura Ense Group - A Self-Made Entrepreneur And Executive
kom-180-proposal-for-a-directive-amending-directive-2014-45-eu-and-directive-...
Traveri Digital Marketing Seminar 2025 by Corey and Jessica Perlman
Katrina Stoneking: Shaking Up the Alcohol Beverage Industry
Types of control:Qualitative vs Quantitative

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