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

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を作ってみた
1 of 41

Recommended

KubeCon EU 2016: Custom Volume Plugins by
KubeCon EU 2016: Custom Volume PluginsKubeCon EU 2016: Custom Volume Plugins
KubeCon EU 2016: Custom Volume PluginsKubeAcademy
340 views44 slides
Perl Bag of Tricks - Baltimore Perl mongers by
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongersbrian d foy
2.3K views26 slides
vfsStream - a better approach for file system dependent tests by
vfsStream - a better approach for file system dependent testsvfsStream - a better approach for file system dependent tests
vfsStream - a better approach for file system dependent testsFrank Kleine
3.2K views39 slides
Parsing JSON with a single regex by
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regexbrian d foy
34.7K views22 slides
vfsStream - effective filesystem mocking by
vfsStream - effective filesystem mocking vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking Sebastian Marek
5K views33 slides
The Magic Of Tie by
The Magic Of TieThe Magic Of Tie
The Magic Of Tiebrian d foy
1.9K views19 slides

More Related Content

What's hot

Perl 5.28 new features by
Perl 5.28 new featuresPerl 5.28 new features
Perl 5.28 new featuresbrian d foy
6.1K views12 slides
File Space Usage Information and EMail Report - Shell Script by
File Space Usage Information and EMail Report - Shell ScriptFile Space Usage Information and EMail Report - Shell Script
File Space Usage Information and EMail Report - Shell ScriptVCP Muthukrishna
3.8K views2 slides
Shell Script to Extract IP Address, MAC Address Information by
Shell Script to Extract IP Address, MAC Address InformationShell Script to Extract IP Address, MAC Address Information
Shell Script to Extract IP Address, MAC Address InformationVCP Muthukrishna
4.1K views2 slides
Bash Script Disk Space Utilization Report and EMail by
Bash Script Disk Space Utilization Report and EMailBash Script Disk Space Utilization Report and EMail
Bash Script Disk Space Utilization Report and EMailVCP Muthukrishna
4.7K views3 slides
Perl 6 by example by
Perl 6 by examplePerl 6 by example
Perl 6 by exampleAndrew Shitov
1.7K views66 slides
JIP Pipeline System Introduction by
JIP Pipeline System IntroductionJIP Pipeline System Introduction
JIP Pipeline System Introductionthasso23
717 views30 slides

What's hot(20)

Perl 5.28 new features by brian d foy
Perl 5.28 new featuresPerl 5.28 new features
Perl 5.28 new features
brian d foy6.1K views
File Space Usage Information and EMail Report - Shell Script by VCP Muthukrishna
File Space Usage Information and EMail Report - Shell ScriptFile Space Usage Information and EMail Report - Shell Script
File Space Usage Information and EMail Report - Shell Script
VCP Muthukrishna3.8K views
Shell Script to Extract IP Address, MAC Address Information by VCP Muthukrishna
Shell Script to Extract IP Address, MAC Address InformationShell Script to Extract IP Address, MAC Address Information
Shell Script to Extract IP Address, MAC Address Information
VCP Muthukrishna4.1K views
Bash Script Disk Space Utilization Report and EMail by VCP Muthukrishna
Bash Script Disk Space Utilization Report and EMailBash Script Disk Space Utilization Report and EMail
Bash Script Disk Space Utilization Report and EMail
VCP Muthukrishna4.7K views
JIP Pipeline System Introduction by thasso23
JIP Pipeline System IntroductionJIP Pipeline System Introduction
JIP Pipeline System Introduction
thasso23717 views
GettingStartedWithPHP by Nat Weerawan
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
Nat Weerawan818 views
Hands on Hadoop by Paul Tarjan
Hands on HadoopHands on Hadoop
Hands on Hadoop
Paul Tarjan1.4K views
Perl v5.26 Features (AmsterdamX.pm) by brian d foy
Perl v5.26 Features (AmsterdamX.pm)Perl v5.26 Features (AmsterdamX.pm)
Perl v5.26 Features (AmsterdamX.pm)
brian d foy776 views
Process monitoring in UNIX shell scripting by Dan Morrill
Process monitoring in UNIX shell scriptingProcess monitoring in UNIX shell scripting
Process monitoring in UNIX shell scripting
Dan Morrill5.3K views
Cis 216 – shell scripting by Dan Morrill
Cis 216 – shell scriptingCis 216 – shell scripting
Cis 216 – shell scripting
Dan Morrill500 views

Viewers also liked

Rデータフレーム自由自在 by
Rデータフレーム自由自在Rデータフレーム自由自在
Rデータフレーム自由自在Takeshi Arabiki
24.3K views49 slides
R言語で統計分類基本 by
R言語で統計分類基本R言語で統計分類基本
R言語で統計分類基本Paweł Rusin
9.4K views22 slides
Rによる分類木 入門 by
Rによる分類木 入門Rによる分類木 入門
Rによる分類木 入門Hiro47
11K views28 slides
Fluentd,mongo db,rでお手軽ログ解析環境 by
Fluentd,mongo db,rでお手軽ログ解析環境Fluentd,mongo db,rでお手軽ログ解析環境
Fluentd,mongo db,rでお手軽ログ解析環境Michitaka Iida
6K views10 slides
Tokyo r50 beginner_2 by
Tokyo r50 beginner_2Tokyo r50 beginner_2
Tokyo r50 beginner_2Takashi Minoda
4.7K views36 slides
Collaborativefilteringwith r by
Collaborativefilteringwith rCollaborativefilteringwith r
Collaborativefilteringwith rTeito Nakagawa
8.3K views45 slides

Viewers also liked(12)

Rデータフレーム自由自在 by Takeshi Arabiki
Rデータフレーム自由自在Rデータフレーム自由自在
Rデータフレーム自由自在
Takeshi Arabiki24.3K views
R言語で統計分類基本 by Paweł Rusin
R言語で統計分類基本R言語で統計分類基本
R言語で統計分類基本
Paweł Rusin9.4K views
Rによる分類木 入門 by Hiro47
Rによる分類木 入門Rによる分類木 入門
Rによる分類木 入門
Hiro4711K views
Fluentd,mongo db,rでお手軽ログ解析環境 by Michitaka Iida
Fluentd,mongo db,rでお手軽ログ解析環境Fluentd,mongo db,rでお手軽ログ解析環境
Fluentd,mongo db,rでお手軽ログ解析環境
Michitaka Iida6K views
Collaborativefilteringwith r by Teito Nakagawa
Collaborativefilteringwith rCollaborativefilteringwith r
Collaborativefilteringwith r
Teito Nakagawa8.3K views
Rでコンジョイント分析 by osamu morimoto
Rでコンジョイント分析Rでコンジョイント分析
Rでコンジョイント分析
osamu morimoto29.2K views
「plyrパッケージで君も前処理スタ☆」改め「plyrパッケージ徹底入門」 by Nagi Teramo
「plyrパッケージで君も前処理スタ☆」改め「plyrパッケージ徹底入門」「plyrパッケージで君も前処理スタ☆」改め「plyrパッケージ徹底入門」
「plyrパッケージで君も前処理スタ☆」改め「plyrパッケージ徹底入門」
Nagi Teramo26.3K views
クックパッド特売情報 における自然言語処理 〜固有表現抽出を利用した検索システム〜 by Takeshi Arabiki
クックパッド特売情報 における自然言語処理 〜固有表現抽出を利用した検索システム〜クックパッド特売情報 における自然言語処理 〜固有表現抽出を利用した検索システム〜
クックパッド特売情報 における自然言語処理 〜固有表現抽出を利用した検索システム〜
Takeshi Arabiki10.9K views
R-3.0.0でGLM by Kazuya Wada
R-3.0.0でGLMR-3.0.0でGLM
R-3.0.0でGLM
Kazuya Wada4.9K views

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

Introduction to Perl by
Introduction to PerlIntroduction to Perl
Introduction to PerlDave Cross
3.3K views152 slides
20 modules i haven't yet talked about by
20 modules i haven't yet talked about20 modules i haven't yet talked about
20 modules i haven't yet talked aboutTatsuhiko Miyagawa
4.9K views78 slides
You Can Do It! Start Using Perl to Handle Your Voyager Needs by
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsRoy Zimmer
1K views112 slides
Introduction to Perl - Day 1 by
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1Dave Cross
58.5K views141 slides
Modern Getopt for Command Line Processing in Perl by
Modern Getopt for Command Line Processing in PerlModern Getopt for Command Line Processing in Perl
Modern Getopt for Command Line Processing in PerlNova Patch
1.5K views48 slides
Perl Presentation by
Perl PresentationPerl Presentation
Perl PresentationSopan Shewale
4.9K views62 slides

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

Introduction to Perl by Dave Cross
Introduction to PerlIntroduction to Perl
Introduction to Perl
Dave Cross3.3K views
You Can Do It! Start Using Perl to Handle Your Voyager Needs by Roy Zimmer
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager Needs
Roy Zimmer1K views
Introduction to Perl - Day 1 by Dave Cross
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1
Dave Cross58.5K views
Modern Getopt for Command Line Processing in Perl by Nova Patch
Modern Getopt for Command Line Processing in PerlModern Getopt for Command Line Processing in Perl
Modern Getopt for Command Line Processing in Perl
Nova Patch1.5K views
I, For One, Welcome Our New Perl6 Overlords by heumann
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlords
heumann715 views
Groovy by Zen Urban
GroovyGroovy
Groovy
Zen Urban1.1K views
Good Evils In Perl (Yapc Asia) by Kang-min Liu
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu8.9K views
DPC 2012 : PHP in the Dark Workshop by Jeroen Keppens
DPC 2012 : PHP in the Dark WorkshopDPC 2012 : PHP in the Dark Workshop
DPC 2012 : PHP in the Dark Workshop
Jeroen Keppens3.7K views
Achieving Parsing Sanity In Erlang by Sean Cribbs
Achieving Parsing Sanity In ErlangAchieving Parsing Sanity In Erlang
Achieving Parsing Sanity In Erlang
Sean Cribbs832 views
Hidden treasures of Ruby by Tom Crinson
Hidden treasures of RubyHidden treasures of Ruby
Hidden treasures of Ruby
Tom Crinson578 views
Bag of tricks by brian d foy
Bag of tricksBag of tricks
Bag of tricks
brian d foy4.4K views
Aura Project for PHP by Hari K T
Aura Project for PHPAura Project for PHP
Aura Project for PHP
Hari K T6K views

More from Takeshi Arabiki

開発の心得 by
開発の心得開発の心得
開発の心得Takeshi Arabiki
5K views18 slides
Introduction to Japanese Morphological Analysis by
Introduction to Japanese Morphological AnalysisIntroduction to Japanese Morphological Analysis
Introduction to Japanese Morphological AnalysisTakeshi Arabiki
16.8K views25 slides
R による文書分類入門 by
R による文書分類入門R による文書分類入門
R による文書分類入門Takeshi Arabiki
30.7K views59 slides
Rのデータ構造とメモリ管理 by
Rのデータ構造とメモリ管理Rのデータ構造とメモリ管理
Rのデータ構造とメモリ管理Takeshi Arabiki
15.2K views22 slides
HTML5 Canvas で学ぶアフィン変換 by
HTML5 Canvas で学ぶアフィン変換HTML5 Canvas で学ぶアフィン変換
HTML5 Canvas で学ぶアフィン変換Takeshi Arabiki
8.9K views29 slides
Introduction to Favmemo for Immature Engineers by
Introduction to Favmemo for Immature EngineersIntroduction to Favmemo for Immature Engineers
Introduction to Favmemo for Immature EngineersTakeshi Arabiki
2.9K views21 slides

More from Takeshi Arabiki(15)

Introduction to Japanese Morphological Analysis by Takeshi Arabiki
Introduction to Japanese Morphological AnalysisIntroduction to Japanese Morphological Analysis
Introduction to Japanese Morphological Analysis
Takeshi Arabiki16.8K views
R による文書分類入門 by Takeshi Arabiki
R による文書分類入門R による文書分類入門
R による文書分類入門
Takeshi Arabiki30.7K views
Rのデータ構造とメモリ管理 by Takeshi Arabiki
Rのデータ構造とメモリ管理Rのデータ構造とメモリ管理
Rのデータ構造とメモリ管理
Takeshi Arabiki15.2K views
HTML5 Canvas で学ぶアフィン変換 by Takeshi Arabiki
HTML5 Canvas で学ぶアフィン変換HTML5 Canvas で学ぶアフィン変換
HTML5 Canvas で学ぶアフィン変換
Takeshi Arabiki8.9K views
Introduction to Favmemo for Immature Engineers by Takeshi Arabiki
Introduction to Favmemo for Immature EngineersIntroduction to Favmemo for Immature Engineers
Introduction to Favmemo for Immature Engineers
Takeshi Arabiki2.9K views
Rのスコープとフレームと環境と by Takeshi Arabiki
Rのスコープとフレームと環境とRのスコープとフレームと環境と
Rのスコープとフレームと環境と
Takeshi Arabiki3.2K views
twitteRで快適Rライフ! by Takeshi Arabiki
twitteRで快適Rライフ!twitteRで快適Rライフ!
twitteRで快適Rライフ!
Takeshi Arabiki8.4K views
RではじめるTwitter解析 by Takeshi Arabiki
RではじめるTwitter解析RではじめるTwitter解析
RではじめるTwitter解析
Takeshi Arabiki23.6K views
文字列カーネルによる辞書なしツイート分類 〜文字列カーネル入門〜 by Takeshi Arabiki
文字列カーネルによる辞書なしツイート分類 〜文字列カーネル入門〜文字列カーネルによる辞書なしツイート分類 〜文字列カーネル入門〜
文字列カーネルによる辞書なしツイート分類 〜文字列カーネル入門〜
Takeshi Arabiki9.5K views
はじめてのまっぷりでゅ〜す by Takeshi Arabiki
はじめてのまっぷりでゅ〜すはじめてのまっぷりでゅ〜す
はじめてのまっぷりでゅ〜す
Takeshi Arabiki2.3K views
TwitterのデータをRであれこれ by Takeshi Arabiki
TwitterのデータをRであれこれTwitterのデータをRであれこれ
TwitterのデータをRであれこれ
Takeshi Arabiki13.5K views
Twitterのデータを取得する準備 by Takeshi Arabiki
Twitterのデータを取得する準備Twitterのデータを取得する準備
Twitterのデータを取得する準備
Takeshi Arabiki2.8K views

Recently uploaded

Presentation on proposed acquisition of leading European asset manager Aermon... by
Presentation on proposed acquisition of leading European asset manager Aermon...Presentation on proposed acquisition of leading European asset manager Aermon...
Presentation on proposed acquisition of leading European asset manager Aermon...KeppelCorporation
171 views11 slides
Mistakes Young Entrepreneurs Make When Approaching Problem Solving by
Mistakes Young Entrepreneurs Make When Approaching Problem SolvingMistakes Young Entrepreneurs Make When Approaching Problem Solving
Mistakes Young Entrepreneurs Make When Approaching Problem SolvingYasser Takie Eddine Abdesselam
48 views31 slides
Accel_Series_2023Autumn_En.pptx by
Accel_Series_2023Autumn_En.pptxAccel_Series_2023Autumn_En.pptx
Accel_Series_2023Autumn_En.pptxNTTDATA INTRAMART
117 views75 slides
Cookie Business Plan Example by
Cookie Business Plan ExampleCookie Business Plan Example
Cookie Business Plan ExampleJessica Larson
20 views50 slides
sample.potx by
sample.potxsample.potx
sample.potxMaryna Yurchenko
14 views3 slides
Top 10 Web Development Companies in California by
Top 10 Web Development Companies in CaliforniaTop 10 Web Development Companies in California
Top 10 Web Development Companies in CaliforniaTopCSSGallery
44 views27 slides

Recently uploaded(20)

Presentation on proposed acquisition of leading European asset manager Aermon... by KeppelCorporation
Presentation on proposed acquisition of leading European asset manager Aermon...Presentation on proposed acquisition of leading European asset manager Aermon...
Presentation on proposed acquisition of leading European asset manager Aermon...
KeppelCorporation171 views
Top 10 Web Development Companies in California by TopCSSGallery
Top 10 Web Development Companies in CaliforniaTop 10 Web Development Companies in California
Top 10 Web Development Companies in California
TopCSSGallery44 views
bookmyshow-1.pptx by 125071035
bookmyshow-1.pptxbookmyshow-1.pptx
bookmyshow-1.pptx
12507103511 views
NYKAA PPT .pptx by 125071081
NYKAA PPT .pptxNYKAA PPT .pptx
NYKAA PPT .pptx
12507108113 views
See the new MTN tariffs effected November 28, 2023 by Kweku Zurek
See the new MTN tariffs effected November 28, 2023See the new MTN tariffs effected November 28, 2023
See the new MTN tariffs effected November 28, 2023
Kweku Zurek29.4K views
Top 10 IT Tasks Small Businesses Can Entrust to Offshore Professionals by altafhsayyednimetler
Top 10 IT Tasks Small Businesses Can Entrust to Offshore ProfessionalsTop 10 IT Tasks Small Businesses Can Entrust to Offshore Professionals
Top 10 IT Tasks Small Businesses Can Entrust to Offshore Professionals
The Truth About Customer Journey Mapping by Aggregage
The Truth About Customer Journey MappingThe Truth About Customer Journey Mapping
The Truth About Customer Journey Mapping
Aggregage60 views
Bloomerang_Forecasting Your Fundraising Revenue 2024.pptx.pdf by Bloomerang
Bloomerang_Forecasting Your Fundraising Revenue 2024.pptx.pdfBloomerang_Forecasting Your Fundraising Revenue 2024.pptx.pdf
Bloomerang_Forecasting Your Fundraising Revenue 2024.pptx.pdf
Bloomerang112 views
Navigating EUDR Compliance within the Coffee Industry by Peter Horsten
Navigating EUDR Compliance within the Coffee IndustryNavigating EUDR Compliance within the Coffee Industry
Navigating EUDR Compliance within the Coffee Industry
Peter Horsten41 views
Group and Teams: Increasing Cooperation and Reducing Conflict by Seta Wicaksana
Group and Teams: Increasing Cooperation and Reducing Conflict Group and Teams: Increasing Cooperation and Reducing Conflict
Group and Teams: Increasing Cooperation and Reducing Conflict
Seta Wicaksana20 views

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