Skip to content

wydty/docf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

使用 docopt 解析函数中的参数, 在命令行中运行函数

安装

remotes::install_github('wydty/docf')

使用方法

定义main 函数

#' 描述。
#'
main <- function(opt, help=F, ...){ "
  \```docopt
  #$ <f> [options]
  <f>   输入的 tsv 文件名称

  #$ abc subcmd [options]
  --pats=<> [default: /path].

  options:
  --th=<threads> Num of threads [default: 10].
  \```
  other text
  " ->  helptxt; if(help) return(helptxt)
  if(F){ ## test ----
    setwd("~/")
    opt <- list(f='')
  }      ## start ----

  pacman::p_load(cli, tidyverse)
  s('开始分析') #-

  cli::cli_alert_success('to: {}')
  s('结束') #-
}

在函数文件的最后一行加上 类似 python 中的 if __name__ == 'main' 语句。

if (!interactive() && sys.nframe() == 0) docf::runfun(main) else main

About

R package

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages