R 开发包 Cookbook
2020-06-08
- 使用 RMarkdown 的
child
参数,进行文档拼接。 - 这样拼接以后的笔记方便复习。
- 相关问题提交到 Issue
1 完成状态
-- R CMD check results --------------------------------------- add2md 1.1.0 ----
Duration: 51.8s
0 errors �� | 0 warnings �� | 0 notes ��
Warning in readChar(path, nchars = file.info(path)$size, ...) :
��non-UTF-8 MBCS���Ի�����ֻ�ܶ�ȡ�ֽ�
R CMD check succeeded
体现了包可以上传了。
2 函数缺少引用
> checking R code for possible problems ... NOTE
get_output: no visible global function definition for 'mutate'
get_url: no visible global function definition for 'map_chr'
Undefined global functions or variables:
map_chr mutate
0 errors �� | 2 warnings x | 2 notes x
Warning in readChar(path, nchars = file.info(path)$size, ...) :
��non-UTF-8 MBCS���Ի�����ֻ�ܶ�ȡ�ֽ�
����: R CMD check found WARNINGs
ִֹͣ��
Exited with status 1.
加上 rer 的包名称。如 mutate
加上 dplyr::
3 ignore 额外文件夹
4 使用 Unicode
参考 https://stackoverflow.com/a/22224027/8625228
-- R CMD check results --------------------------------------- add2md 1.1.0 ----
Duration: 56.7s
> checking R files for non-ASCII characters ... WARNING
Found the following file with non-ASCII characters:
paste_kindle.R
Portable packages must use only ASCII characters in their R code,
except perhaps in comments.
Use \uxxxx escapes for other characters.
5 vignette 报错
E creating vignettes (13.4s)
--- re-building 'introduction.Rmd' using rmarkdown
Quitting from lines 228-229 (introduction.Rmd)
Error: processing vignette 'introduction.Rmd' failed with diagnostics:
û��"relative_path"�������
--- failed re-building 'introduction.Rmd'
--- re-building 'url.Rmd' using rmarkdown
--- finished re-building 'url.Rmd'
SUMMARY: processing the following file failed:
'introduction.Rmd'
����: Vignette re-building failed.
ִֹͣ��
Error in (function (command = NULL, args = character(), error_on_status = TRUE, :
System command error
Calls: <Anonymous> ... eval -> with_envvar -> force -> do.call -> <Anonymous>
ִֹͣ��
Exited with status 1.
删除 depreciated 的函数
6 use_package
> checking package dependencies ... ERROR
Namespace dependencies not required:
'clipr', 'glue', 'rstudioapi', 'rvest', 'usethis', 'xml2'
See section 'The DESCRIPTION file' in the 'Writing R Extensions'
manual.
1 error x | 0 warnings <U+2713> | 0 notes <U+2713>
复制 'clipr', 'glue', 'rstudioapi', 'rvest', 'usethis', 'xml2'
现在可以用 add2pkg::map_use_package
7 去除 library
> checking dependencies in R code ... WARNING
'::' or ':::' imports not declared from:
'here' 'readr' 'stringr' 'yaml'
直接在 utils 加入
复制 'here' 'readr' 'stringr' 'yaml'
"'here' 'readr' 'stringr' 'yaml'" %>%
str_split(" ") %>%
.[[1]] %>%
str_remove_all("'") %>%
paste("#' @import", .) %>%
str_flatten("\n") %>%
clipr::write_clip()
然后增加
8 函数缺少描述
> checking for missing documentation entries ... WARNING
Undocumented code objects:
'm1_v2'
All user-level objects in a package should have documentation entries.
See chapter 'Writing R documentation files' in the 'Writing R
Extensions' manual.
add
#' Build a url in markdown
#'
#' This function helps users to paste url in markdown
#'
#' @param size the figure size, by default, 100 x 100
#' @return Character.
#' @author Jiaxiang Li
#'
#' @import rstudioapi
#' @importFrom stringr str_split str_match str_detect
#' @importFrom glue glue
#' @importFrom rebus %R% or DOT one_or_more LOWER optional capture END
#' @export
9 函数参数缺少描述
> checking Rd \usage sections ... WARNING
Undocumented arguments in documentation object 'build_iframe'
'input' 'is_nbviewer'
Documented arguments not in \usage in documentation object 'build_iframe':
'url'
Undocumented arguments in documentation object 'button'
'...'
Undocumented arguments in documentation object 'center'
'input' 'size'
Undocumented arguments in documentation object 'change_to_upper'
'input'
Undocumented arguments in documentation object 'checkbox'
'input'
Undocumented arguments in documentation object 'extract_firstline'
'url' 'content_path' 'pattern' 'para_length'
Undocumented arguments in documentation object 'extract_highlight'
'url' 'pattern'
Undocumented arguments in documentation object 'get_input'
'input' 'clip' 'collapse'
Undocumented arguments in documentation object 'get_quote'
'input'
Undocumented arguments in documentation object 'get_url'
'input' 'name'
Undocumented arguments in documentation object 'get_url_title'
'url'
Undocumented arguments in documentation object 'get_word_style'
'style'
Undocumented arguments in documentation object 'kbd'
'...'
Undocumented arguments in documentation object 'list_in_order'
'input'
Undocumented arguments in documentation object 'mark'
'...'
Undocumented arguments in documentation object 'naming_dir'
'input' 'sep'
Undocumented arguments in documentation object 'transfer2df'
'raw_text'
Documented arguments not in \usage in documentation object 'transfer2df':
'size'
Functions with \usage entries need to have the appropriate \alias
entries, and all their arguments documented.
The \usage entries must correspond to syntactically valid R code.
See chapter 'Writing R documentation files' in the 'Writing R
Extensions' manual.
一个个添加好
没有 @export
函数,如果增加了多余的参数,也会报错。
10 packrat 删除
> checking if this is a source package ... NOTE
Subdirectory 'packrat/lib/x86_64-apple-darwin15.6.0/3.5.1/packrat' seems to contain an installed version of the package.
直接删除。
11 去除 global variables 的问题
一般 check 时会出现这样的问题,这是使用 .
写 pipline 产生的。
一般有两种方法,
var_list <-
". cutoff fpr key ks tpr value" %>%
strsplit("\\s") %>%
.[[1]] %>%
paste0("\"", ., "\"") %>%
str_flatten(", ")
glue::glue("globalVariables(c({var_list}))") %>%
clipr::write_clip()
注意这里别忘了 c()
,否则报错。
number
是一个包。
-- R CMD check results --------------------------------------- add2gh 0.1.0 ----
Duration: 42.7s
> checking R code for possible problems ... NOTE
collect_comments: no visible binding for global variable 'number'
Undefined global functions or variables:
number
或者,
Quoted arguments in tidyverse functions can trigger an R CMD check NOTE about undefined global variables. To avoid this: 1.Import
rlang::.data
to your package, perhaps with the roxygen2 tag@importFrom rlang .data
2.Use the.data$
pronoun in front of variable names in tidyverse(Developed 2019)
knitr::include_graphics("figure/20200322125624.png")
knitr::include_graphics("figure/20200322125734.png")
12 给函数加上包名
Undefined global functions or variables:
. PC1 abs_err d global_mean lift local_mean m mae_d na.omit name
obs_pctg pos_pctg predict str_remove_all str_sub sysname
write_excel_csv y yhat yhat_bin yr
Consider adding
importFrom("stats", "na.omit", "predict")
to your NAMESPACE file.
类似于这种情况中,显然write_excel_csv
是一个未加上报名的函数。
加完以后记得加上 @import
13 todos 进 commit
放到 commit 最后都可以整理成 NEWS 的!
14 更新 NEWS.md
以包 add2md 为例。
add2git:::commit2news(repo_path = ,min = ,max = )
- updated the function of
checkbox
with the feature checked -> unchecked. - updated the function
checkbox
with the featurechecked
. - reformatted code.
- depreciated the function
append_archive
. - fixed bugs and typos and encoding problems.
- translated non-ASCII characters into unicode, add
@params
args, delete packrat, ignore docs-building, add global variables. - updated imported packages, and remove depreciated functions in vignettes document.
- added the function
add_wechat_portfolio
. - updated the function
diagrammer_shortcut
. - made the function
get_input
exported. - made functions output visible.
- added arg
para_length
for the functionextract_firstline
. - updated license.
把所有 commit 拿出来然后进行整合。 这就是为什么要认真写 commit。
15 CRAN Comments
usethis::use_cran_comments()
usethis::use_build_ignore("cran-comments.md")
创建如下
16 Ignore README.Rmd
参考 https://stackoverflow.com/a/48956446/8625228
usethis::use_build_ignore("README.Rmd")
17 Update DESC
18 保证 README.Rmd 链接都是有效的
19 Add examples, tests, and vignettes
Flavor: r-devel-linux-x86_64-debian-gcc, r-devel-windows-ix86+x86_64
Check: for code which exercises the package, Result: WARNING
No examples, no tests, no vignettes
- 增加
usethis::use_spell_check()
,增加test
- 在 R 加入
@examples
,新建 vignette,加入 - 加入
README.Rmd
,用 child
> usethis::use_test("add_me")
✔ Setting active project to 'D:/work/add2pkg'
✔ Adding 'testthat' to Suggests field in DESCRIPTION
✔ Creating 'tests/testthat/'
✔ Writing 'tests/testthat.R'
● Call `use_test()` to initialize a basic test file and open it for editing.
✔ Increasing 'testthat' version to '>= 2.1.0' in DESCRIPTION
✔ Writing 'tests/testthat/test-add_me.R'
● Modify 'tests/testthat/test-add_me.R'
加上 test
test_that("Plain Text", {
expect_equal(add_me(), 'Authors@R:
person(given = "Jiaxiang",
family = "Li",
role = c("aut", "cre"),
email = "alex.lijiaxiang@foxmail.com",
comment = c(ORCID = "https://orcid.org/0000-0003-3196-6492"))')
})
expect_that(add_bibtex("book"), prints_text())
很好。
加上 vignette
> use_vignette("intro")
✔ Adding 'knitr' to Suggests field in DESCRIPTION
✔ Setting VignetteBuilder field in DESCRIPTION to 'knitr'
✔ Adding 'inst/doc' to '.gitignore'
✔ Creating 'vignettes/'
✔ Adding '*.html', '*.R' to 'vignettes/.gitignore'
✔ Adding 'rmarkdown' to Suggests field in DESCRIPTION
✔ Writing 'vignettes/intro.Rmd'
● Modify 'vignettes/intro.Rmd'
20 release 函数的流程
> devtools::release()
Warning: DR_DEVTOOLS FOUND PROBLEMS
* R is out of date (3.6.0 vs 3.6.2)
* Devtools or dependencies out of date: devtools, callr, cli, covr, digest, DT, httr,
pkgbuild, rlang, roxygen2, testthat, curl, whisker, R6, Rcpp, backports, mime,
openssl, sys, processx, fansi, rex, htmlwidgets, ggplot2, scales, BH, plyr, pillar,
pkgconfig, vctrs, stringi, prettyunits, xml2
* RStudio is out of date (1.2.5001 vs 1.2.5033.1)
Proceed anyway?
1: I forget
2: Not yet
3: Yup
Selection: 3
Have you checked for spelling errors (with `spell_check()`)?
1: I forget
2: For sure
3: No way
Selection: 2
Have you run `R CMD check` locally?
1: Yup
2: Not yet
3: No way
Selection: 1
── Running additional devtools checks for add2pkg ──────────────────────────────
Checking version number has three components... OK
Checking dependencies don't rely on dev versions... OK
Checking vignette titles are not placeholders... OK
Checking NEWS.md is not ignored... OK
Checking NEWS.Rd does not exist... OK
Checking DESCRIPTION doesn't have Remotes field... OK
────────────────────────────────────────────────────────────────────────────────
Were devtool's checks successful?
1: Not yet
2: Definitely
3: No
Selection: 2
Have you checked on R-hub (with `check_rhub()`)?
1: No way
2: I forget
3: Definitely
Selection: 3
Have you checked on win-builder (with `check_win_devel()`)?
1: No way
2: Definitely
3: No
Selection: 2
Have you updated `NEWS.md` file?
1: Yeah
2: Nope
3: Uhhhh... Maybe?
Selection: 1
Have you updated `DESCRIPTION`?
1: No way
2: For sure
3: Nope
Selection: 2
Have you updated `cran-comments.md?`
1: Of course
2: Uhhhh... Maybe?
3: Not yet
Selection: 1
── Running Git checks for add2pkg ──────────────────────────────────────────────
Checking uncommitted files... OK
Checking synchronisation with remote branch... OK
────────────────────────────────────────────────────────────────────────────────
Were Git checks successful?
1: Not yet
2: Yup
3: Uhhhh... Maybe?
Selection: 2
Is your email address alex.lijiaxiang@foxmail.com?
1: No
2: Absolutely
3: Uhhhh... Maybe?
Selection: 2
Building
pdflatex not found! Not building PDF manual.
✓ checking for file 'D:\work\add2pkg/DESCRIPTION' (499ms)
─ preparing 'add2pkg': (1.1s)
✓ checking DESCRIPTION meta-information ... OK
─ installing the package to build vignettes
✓ creating vignettes (7s)
─ checking for LF line-endings in source and make files and shell scripts (352ms)
─ checking for empty or unneeded directories
─ building 'add2pkg_0.2.1.tar.gz'
Submitting file: C:\Users\LIJIAX~1\AppData\Local\Temp\RtmpEdl715/add2pkg_0.2.1.tar.gz
File size: 7.9 Kb
Ready to submit add2pkg (0.2.1) to CRAN?
1: Yes
2: No way
3: Uhhhh... Maybe?
Selection: 1
Uploading package & comments
Confirming submission
Error in if (new_url$query$submit == "1") { : argument is of length zero
21 r-hub 通过示例
自己上传 https://builder.r-hub.io/
地址 https://builder.r-hub.io/status/original/add2pkg_0.2.1.tar.gz-76c7b9d1252c2906bea2aeb92441ec27
22 上传成功后的邮件
Dear maintainer,
package add2pkg_0.2.1.tar.gz has been auto-processed and is pending a manual inspection of this new CRAN submission. A CRAN team member will typically respond to you within the next 10 working days. For technical reasons you may receive a second copy of this message when a team member triggers a new check.
Log dir: <https://win-builder.r-project.org/incoming_pretest/add2pkg_0.2.1_20200113_095008/>;
The files will be removed after roughly 7 days.
Installation time in seconds: 25
Check time in seconds: 144
R Under development (unstable) (2020-01-07 r77633)
Pretests results:
Windows: <https://win-builder.r-project.org/incoming_pretest/add2pkg_0.2.1_20200113_095008/Windows/00check.log>;
Status: 1 NOTE
Debian: <https://win-builder.r-project.org/incoming_pretest/add2pkg_0.2.1_20200113_095008/Debian/00check.log>;
Status: 1 NOTE
No strong reverse dependencies to be checked.
Best regards,
CRAN teams' auto-check service
Flavor: r-devel-linux-x86_64-debian-gcc, r-devel-windows-ix86+x86_64
Check: CRAN incoming feasibility, Result: NOTE
Maintainer: 'Jiaxiang Li <alex.lijiaxiang@foxmail.com>'
New submission
Found the following (possibly) invalid file URI:
URI: CODE_OF_CONDUCT.md
From: README.md
23 包含其他文件在包中
Thanks, we see:
Found the following (possibly) invalid file URI:
URI: CODE_OF_CONDUCT.md
From: README.md
Please include the file or link to it via a fully specified URL.
果然 build 里面是没有 COC 和 LICENSE.md
> dir_tree("../add2pkg_0.2.1/add2pkg", recurse = F)
../add2pkg_0.2.1/add2pkg
+-- build
+-- DESCRIPTION
+-- inst
+-- LICENSE
+-- man
+-- NAMESPACE
+-- NEWS.md
+-- R
+-- README.md
+-- tests
\-- vignettes
r package build include file
.Rbuildignore
删除
> checking top-level files ... NOTE
Non-standard files/directories found at top level:
'CODE_OF_CONDUCT.md' 'LICENSE.md'
0 errors <U+2713> | Warning in readChar(path, nchars = file.info(path)$size, ...) :
��non-UTF-8 MBCS���Ի�����ֻ�ܶ�ȡ�ֽ�
0 warnings <U+2713> | 1 note x
R CMD check succeeded
所以最好的策略是用绝对的 GitHub 链接,不要把这种文件链接用相对路径加入到包中,所以修改函数。
24 好好写 Description
Perhaps elaborate in the Description field what the package is capable of.
Please fix and resubmit.
Best,
Uwe Ligges
Description 写的太简单了。
26 fix mis-spelling
> update_wordlist()
DESCRIPTION does not contain 'Language' field. Defaulting to 'en-US'.
The following words will be added to the wordlist:
- asis
- BibTex
- coc
- descripton
- dev
- DOI
- Infomation
- params
- README
- zenodo
- Zenodo
Are you sure you want to update the wordlist?
1: Yes
2: No
所以完全弄干净后,再更新 wordlist
配合document();spell_check()
完成。
27 增加数据
I highly recommend taking the time to include the code used to do this in the source version of your package. This will make it easy for you to update or reproduce your version of the data. I suggest that you put this code in
data-raw/
http://r-pkgs.had.co.nz/data.html
这里需要保留数据的复现方式和数据。
参考 https://github.com/hadley/babynames/blob/master/data-raw/applicants.R
我这里使用
usethis::use_data_raw("文件名")
然后给复现例子。
## code to prepare `two_class_example` dataset goes here
library(yardstick)
data("two_class_example")
library(tidyverse)
two_class_example_edited <-
two_class_example %>%
transmute(
y = ifelse(truth == "Class1",1,0)
,yhat = Class1
)
two_class_example_edited %>% head
two_class_example_edited %>%
write_excel_csv("data-raw/two_class_example.csv")
usethis::use_data(two_class_example_edited, overwrite = TRUE)
然后增加例子。
29 增加数据文档
-- R CMD check results ----------------------------------- rawKS 0.0.0.9000 ----
Duration: 1m 7.2s
> checking for missing documentation entries ... WARNING
Undocumented code objects:
'ks_plot' 'two_class_example_edited'
Undocumented data sets:
'two_class_example_edited'
All user-level objects in a package should have documentation entries.
See chapter 'Writing R documentation files' in the 'Writing R
Extensions' manual.
如模板
#' Prices of 50,000 round cut diamonds.
#'
#' A dataset containing the prices and other attributes of almost 54,000
#' diamonds.
#'
#' @format A data frame with 53940 rows and 10 variables:
#' \describe{
#' \item{price}{price, in US dollars}
#' \item{carat}{weight of the diamond, in carats}
#' ...
#' }
#' @source \url{http://www.diamondse.info/}
"diamonds"
再如
#' A sample with the target and predictions
#'
#' A dataset containing two columns, \code{yhat} and \code{y} as
#' the inputs for the function \code{ks_table}.
#'
#' @format A data frame with 500 rows and 2 variables:
#' \describe{
#' \item{yhat}{predictions}
#' \item{y}{target}
#' }
#' @source package \code{yardstick::two_class_example}
"two_class_example_edited"
30 加入 R 版本
-- R CMD check results ----------------------------------- rawKS 0.0.0.9000 ----
Duration: 44.8s
> checking data for ASCII and uncompressed saves ... WARNING
Warning: package needs dependence on R (>= 2.10)
0 errors <U+2713> | 1 warning x | 0 notes <U+2713>
Warning in readChar(path, nchars = file.info(path)$size, ...) :
��non-UTF-8 MBCS���Ի�����ֻ�ܶ�ȡ�ֽ�
����: R CMD check found WARNINGs
ִֹͣ��
Exited with status 1.
R 版本没有限制, 参考 https://github.com/USGS-R/loadflex/issues/25
31 R 版本限制
-- R CMD check results ----------------------------------- add2bibtex 0.5.2 ----
Duration: 48.8s
> checking DESCRIPTION meta-information ... WARNING
Dependence on R version '3.5.1' not with patchlevel 0
Version: 0.5.2
Authors@R:
person(given = "Jiaxiang",
family = "Li",
role = c("aut", "cre"),
email = "alex.lijiaxiang@foxmail.com",
comment = c(ORCID = "https://orcid.org/0000-0003-3196-6492"))
Description: Easily Adding Bibliographies and Citations.
Depends: R (>= 3.5.1)
参考 https://stackoverflow.com/a/48433479/8625228
这里如果 Version 要 0.5.2
,那么Depends: R (>= 3.5.1)
中改为3.5.0
。
32 查看 non-ASCII 文本
-- R CMD check results ----------------------------------- add2bibtex 0.5.2 ----
Duration: 1m 60s
> checking R files for non-ASCII characters ... WARNING
Found the following files with non-ASCII characters:
add_amazon_cn.R
add_bibtex.R
add_wechat.R
Portable packages must use only ASCII characters in their R code,
except perhaps in comments.
Use \uxxxx escapes for other characters.
33 注意 non-ACSII 在 Rd 的出现
- checking PDF version of manual without hyperrefs or index … ERROR https://builder.r-hub.io/status/add2bibtex_0.5.2.tar.gz-09adbbfcbe3f639a67fc783068b40898
在 R 文件中
add_tail_refs <-
function(path = "jiangning_weaving/analysis/para_length_5_notes.Rmd", append_text = '[@\u5434\u851a_2017\u6c5f\u5b81\u7ec7\u9020]') {
lines <- readr::read_lines(path)
quote_index <- lines %>%
stringr::str_which("^>\\s")
lines[quote_index] <- paste(lines[quote_index], append_text)
lines %>% readr::write_lines(path)
}
进行了 unicode 转码,但是在 .Rd
文件中变成了中文。
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/add_tail_refs.R
\name{add_tail_refs}
\alias{add_tail_refs}
\title{Add reference tag into quote paragraphs.}
\usage{
add_tail_refs(path = "jiangning_weaving/analysis/para_length_5_notes.Rmd",
append_text = "[@吴蔚_2017江宁织造")
}
\arguments{
\item{path}{The RMarkdown document path.}
\item{append_text}{The BibTex alias.}
}
\description{
Add reference tag into quote paragraphs.
}
34 删除不用的包
Build ID: add2md_1.1.1.tar.gz-20e671205873580fb77ce80d9cce7aae
Platform: Debian Linux, R-devel, GCC
Submitted: 18 minutes 44.5 seconds ago
Build time: 18 minutes 42.2 seconds
NOTES:
* checking dependencies in R code ... NOTE
Namespaces in Imports field not imported from:
‘data.tree’ ‘git2r’ ‘tibble’
All declared Imports should be used.
35 回复速度
的确是晚上回复比较快。
36 标题大小写问题
Thanks, we see:
The Title field should be in title case. Current version is:
'Easily get TPR, FPR and KS statistic'
In title case that is:
'Easily Get TPR, FPR and KS Statistic'
注意这里 除了 in
, and
进行小写以外,Get
需要大写。
可以参考 https://cran.r-project.org/web/packages/gluedown/
gluedown: Wrap Vectors in Markdown Formatting
37 elaborate Description
In the Description field, pelase elaborate. Is there some reference
about the method you can add in the Description field in the form
Authors (year) <doi:.....>?
Please fix and resubmit.
这是 gluedown 的模板 https://github.com/kiernann/gluedown/blob/master/DESCRIPTION
Ease the transition between R vectors and markdown text. With ‘gluedown’ and ‘rmarkdown’, users can create traditional vectors in R, glue those strings together with the markdown syntax, and print those formatted vectors directly to the document. This package primarily uses GitHub Flavored Markdown (GFM), an offshoot of the unambiguous CommonMark specification by John MacFarlane (2019) https://spec.commonmark.org/.
最后的完成情况。
The “K–S statistic” is a standard method to measure the model strength for credit risk scoring models. This package calculates the “K–S statistic” and plots the true-positive rate and false-positive rate to measure the model strength. This package was written with the credit marketer, who uses risk models in conjunction with his campaigns. The users could read more details from Thrasher (1992) doi:https://doi.org/10.1002/dir.4000060408 and a Python version ‘pyks’ https://pypi.org/project/pyks/.
也参考 https://www.jianshu.com/p/aee69df9e041
authors (year) <doi:...>
authors (year) <arXiv:...>
authors (year, ISBN:...)
<https:...>
38 标题特殊拼写处理
不确定的话,就全部用 title case 完成,如包 bibtex
这样重复的话,用 readme read child 放过来。
bibtex: Bibtex Parser
39 失效的链接
New submission
Found the following (possibly) invalid URLs:
URL: https://raw.githubusercontent.com/JiaxiangBU/picbackup/master/add2blog_sample_wallpaper.png
From: inst/doc/introduction.html
Status: 404
Message: Not Found
Found the following (possibly) invalid file URIs:
URI: www.example.com
From: inst/doc/url.html
URI: weirdlink
From: inst/doc/url.html
URI: data/whitehouse.csv
From: inst/doc/url.html
URI: app.yinxiang.com
From: inst/doc/url.html
URI: app.evernote.com
From: inst/doc/url.html
URI: .github/CODE_OF_CONDUCT.md
From: README.md
URI: LICENSE.md
From: README.md
Flavor: r-devel-linux-x86_64-debian-gcc, r-devel-windows-ix86+x86_64
Check: package vignettes, Result: NOTE
Package vignette with placeholder title 'Vignette Title':
'url.Rmd'
这种链接只是用来举例子的,不一定真的存在,所以直接消除。
40 bib 文件的位置
参考 https://github.com/yihui/knitr/blob/master/inst/examples/knitr-manual.bib
放在 inst/examples
41 默认函数加上 import
> checking R code for possible problems ... NOTE
irr: no visible global function definition for 'optimise'
Undefined global functions or variables:
optimise
Consider adding
importFrom("stats", "optimise")
to your NAMESPACE file.
0 errors <U+2713> | 3 warnings x | 2 notes x
����: R CMD check found WARNINGs
ִֹͣ��
Exited with status 1.
这里 importFrom("stats", "optimise")
是的确的。
42 pending a manual inspection
package rawKS_0.1.0.tar.gz has been auto-processed and is pending a manual inspection. A CRAN team member will typically respond to you within the next 5 working days. For technical reasons you may receive a second copy of this message when a team member triggers a new check.
这个一般会缩短到5个工作日内回复。
43 正确的DOI书写
Found the following (possibly) invalid URLs:
URL: https://doi.org/10.1002/dir.4000060408
From: DESCRIPTION
Status: Error
Message: libcurl error code 28:
Failed to connect to doi.wiley.com port 80: Connection timed out
Found the following (possibly) invalid DOIs:
DOI: https://doi.org/10.1002/dir.4000060408
From: DESCRIPTION
Message: Invalid DOI
The Description field contains
<doi:https://doi.org/10.1002/dir.4000060408>; and a Python version
Please enclose URLs in angle brackets (<...>).
The Description field contains
<doi:https://doi.org/10.1002/dir.4000060408>; and a Python version
Please write DOIs as <doi:10.prefix/suffix>.
以下为例,参考 https://onlinelibrary.wiley.com/action/showCitFormats?doi=10.1002%2Fdir.4000060408
Thrasher, R.P. (1992), A note on the use of the K–S statistic as a measure of model strength. J. Direct Mark., 6: 40-47. doi:10.1002/dir.4000060408
doi:10.1002/dir.4000060408
就是我们需要的,格式为<doi:10.prefix/suffix>
44 Vignette yaml 报错
New submission
Flavor: r-devel-linux-x86_64-debian-gcc, r-devel-windows-ix86+x86_64
Check: package vignettes, Result: NOTE
Package vignette with placeholder title 'Vignette Title':
'more_for_url.Rmd'
---
title: "More for URL"
author: "Jiaxiang Li"
date: "2020-06-08"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Vignette Title}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
在对应的 vignette 中 yaml 写着%\VignetteIndexEntry{Vignette Title}
,没有自定义导致的。
45 DESC 避免使用双引号
Thanks, we see:
Found the following (possibly) invalid DOIs:
DOI: https://doi.org/10.1002/dir.4000060408
From: DESCRIPTION
Message: Invalid DOI
The Description field contains
<doi:https://doi.org/10.1002/dir.4000060408>; and a Python version
Please enclose URLs in angle brackets (<...>).
The Description field contains
<doi:https://doi.org/10.1002/dir.4000060408>; and a Python version
Please write DOIs as <doi:10.prefix/suffix>.
Please do not use directed quotes as in “K–S statistic” in the
Description but undirected ones, i.e. "KS....".
- Use undirected quotes, Kolmogorov-Smirnov (K-S) statistic instead of “K–S statistic”.
46 Python 包也用单引号
a Python version ‘pyks’ https://pypi.org/project/pyks/
- Quote softare names in the right way.
47 使用拼写检查就会产生test
> use_spell_check()
✔ Setting active project to 'D:/work/add2pkg'
✔ Adding 'spelling' to Suggests field in DESCRIPTION
✔ Setting Language field in DESCRIPTION to 'en-US'
No changes required to D:\work\add2pkg\inst\WORDLIST
Updated D:/work/add2pkg/tests/spelling.R
● Run `devtools::check()` to trigger spell check
48 不要重复上传
The Server already contains a file with that name/version, please increase version number
49 复制功能的取舍
复制功能在 rhub 测试时,因为系统不一样容易报错。
增加一个 is_paste
方便构建测试。
ERRORS:
* checking examples ... ERROR
Running examples in ‘add2bibtex-Ex.R’ failed
The error most likely occurred in:
> ### Name: add_bibtex
> ### Title: Bibtex and Biblatex Template
> ### Aliases: add_bibtex
>
> ### ** Examples
>
> add_bibtex("online")
Error: Clipboard on X11 requires 'xclip' (recommended) or 'xsel'.
Execution halted
WARNINGS:
* checking re-building of vignette outputs ... WARNING
Error(s) in re-building vignettes:
...
--- re-building ‘intro.Rmd’ using rmarkdown
Quitting from lines 22-23 (intro.Rmd)
Error: processing vignette 'intro.Rmd' failed with diagnostics:
Clipboard on X11 requires 'xclip' (recommended) or 'xsel'.
--- failed re-building ‘intro.Rmd’
SUMMARY: processing the following file failed:
‘intro.Rmd’
Error: Vignette re-building failed.
Execution halted
50 mis-spelling arguement
参考 https://github.com/robbriers/biotic/blob/master/cran-comments.Rmd 可以写
51 mis-spelling
- GitBook -> git book
- RMarkdown -> R markdown
52 子路径内存太大
53 函数说明不要太长
-- R CMD check results --------------------------------- add2datacamp 0.1.1 ----
Duration: 50.4s
> checking Rd line widths ... NOTE
Rd file 'download_datacamp_slides.Rd':
\usage lines wider than 90 characters:
download_datacamp_slides(input = "https://s3.amazonaws.com/assets.datacamp.com/production/course_15268/slides/chapter{1:4}.pdf",
但是如果链接很长怎么办? 处理方法
"https://s3.amazonaws.com/assets.datacamp.com/production/course_15268/slides/chapter1.pdf" ==
file.path(
"https://s3.amazonaws.com/assets.datacamp.com/production",
"course_15268/slides/chapter1.pdf"
)
## [1] TRUE
54 更新 LICENSE 年份
Should the year of the LICENSE file be updated?
55 合理写 title
"The mandatory ‘Title’ field should give a short description of the package"
Please choose a more meaningful title.
The Title field should give a short description of the package. It should be capitalized, not use any markup, not have any continuation lines, and not end in a period. Older versions of R used a separate file TITLE for giving this information; this is now defunct, and the Title field in DESCRIPTION is required.
参考 https://cran.r-project.org/web/packages/knitr/index.html
add2pkg: A Assistant Package for Package Development in R
56 写函数的 return
Please add \value to .Rd files regarding exported methods and explain
the functions results in the documentation.
(See: Writing R Extensions
<https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Documenting-functions>
)
If a function does not return a value, please document that too, e.g.
\value{None}.
这只是针对 @export
的(regarding exported methods
)
加入@return
,参考 http://r-pkgs.had.co.nz/man.html
如果为空,写入 @return None
#' @return If all inputs are integer and logical, then the output
#' will be an integer. If integer overflow
#' \url{http://en.wikipedia.org/wiki/Integer_overflow} occurs, the output
#' will be NA with a warning. Otherwise it will be a length-one numeric or
#' complex vector.
#'
#' Zero-length vectors have sum 0 by definition. See
#' \url{http://en.wikipedia.org/wiki/Empty_sum} for more details.
57 增加 verbose
You write information messages to the console that cannot be easily
suppressed.
It is more R like to generate objects that can be used to extract the
information a user is interested in, and then print() that object.
Instead of print()/cat() rather use message()/warning() or
if(verbose)cat(..) if you really have to write text to the console.
(except for print() and summary() functions)
Please fix and resubmit.
Best,
Martina Schmirl
使用 if(verbose)
cat(…) 打印信息。
58 missing name and title
Writing NAMESPACE
Warning message:
which_license.Rd is missing name/title. Skipping
函数没有加 title。
59 warning example doesn’t exist
60 DESC 不用 title case
61 GitHub 等名字用引号括起来
Thanks,
Please always write package names, software names and API names in
single quotes in title and description. e.g: --> 'add2gh'
62 外部文件如何写 vignette
Please add small files needed for the examples in the inst/extdata
subfolder of your package and use system.file() to get the correct
package path.
system.file()
反馈的是路径。
参考 https://stackoverflow.com/questions/13463103/inst-and-extdata-folders-in-r-packaging 例如 add2ggplot 包,这样写
add_logo(
plot_path = system.file("extdata", "logo.png", package = "add2ggplot"),
logo_path = system.file("extdata", "jiaxiang.png", package = "add2ggplot"),
logo_position = "bottom right",
logo_scale = 5
)
在 vignette 些例子。
写可以共享的路径地址。
Please ensure that your functions do not write by default or in your
examples/vignettes/tests in the user's homspace filee (including the
package directory and getwd()). That is not allowed by CRAN policies.
Please only write/save files if the user has specified a directory in
the function themselves. Therefore please omit any default path =
getwd() in writing functions.
In your examples/vignettes/tests you can write to tempdir().
检查
- examples/
- vignettes/
tests
63 dontrun 只用一个
(It also cannot work that way anyway as 1 \dontrun{} should be wrapped
around all the code that should not be run - not one per line)
Please fix and resubmit.
Best,
Martina Schmirl
64 export 函数的要求
Please add small executable examples in your Rd-files to illustrate the
use of the exported function but also enable automatic testing.
放 export 都要给 examples
那些使用 addin 的,把@export
删除。
没有准备好的函数,先不要 export,平时:::
调用就好了。
65 xclip 的问题
加入一个is_paste
进行逃避。
然后 @param
进行解释。
All packages used in the package need to be listed in the DESCRIPTION
file either in 'Depends', 'Suggests', 'Imports', 'Enhances'.
(See Writing R Extenstion
https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Package-Dependencies)
e.g. 'xclip' or 'xsel' for build_iframe()
66 donttest
\dontrun{} should only be used if the example really cannot be executed
(e.g. because of missing additional software, missing API keys, ...) by
the user. That's why wrapping examples in \dontrun{} adds the comment
("# Not run:") as a warning for the user.
Does not seem necessary.
Please replace \dontrun with \donttest.
Please fix and resubmit.
Best,
Martina Schmirl
67 addin check 报错
直接不要 export
-- R CMD check results --------------------------------------- add2md 1.1.1 ----
Duration: 1m 44.4s
> checking examples ... ERROR
Running examples in 'add2md-Ex.R' failed
The error most likely occurred in:
> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: diagrammer_shortcut
> ### Title: Quick paste a DiagrammeR template
> ### Aliases: diagrammer_shortcut
>
> ### ** Examples
>
> diagrammer_shortcut()
Error: RStudio not running
Execution halted
1 error x | 0 warnings <U+2713> | 0 notes <U+2713>
我之前提问过这个问题 https://community.rstudio.com/t/use-check-and-get-error-about-ex-r/18263/4
但是不是重新启动的问题啊,我是用快捷键的,这是干净的呀。
Running examples in ‘-Ex.R’ failed The error most likely occurred in rstudio.dcf
没有找到解决办法。
68 example 和 vignette 写 library
-- R CMD check results ---------------------------------------- rawKS 0.1.0 ----
Duration: 3m 5s
> checking for unstated dependencies in examples ... WARNING
'library' or 'require' call not declared from: 'tidyverse'
就是是在 examples 里面也要写在 imports。
> checking for unstated dependencies in vignettes ... NOTE
'library' or 'require' call not declared from: 'tidyverse'
0 errors <U+2713> | 1 warning x | 2 notes x
69 unable to verify current time
> checking for future file timestamps ... NOTE
unable to verify current time
相关问题 https://community.rstudio.com/t/r-devel-r-cmd-check-failing-because-of-time-unable-to-verify-current-time/25589/3 https://stat.ethz.ch/pipermail/r-package-devel/2019q1/003577.html
70 打开 GitHub Pages
参考 https://github.com/r-lib/gh/issues/107
gh::gh(
"POST /repos/:owner/:repo/pages",
owner = "JiaxiangBU",
repo = "test-gh",
source = list(branch = jsonlite::unbox("master"), path = jsonlite::unbox("")),
.send_headers = c(Accept = "application/vnd.github.switcheroo-preview+json")
)
Error in gh_process_response(raw) : GitHub API error (422): 422 Unprocessable Entity Message: Invalid request. / is not a member of ["", "/docs"]. Read more at https://developer.github.com/v3/repos/pages/#enable-a-pages-site
因此只有["", "/docs"]
两种情况。
{
"url": "https://api.github.com/repos/JiaxiangBU/test-gh/pages",
"status": {},
"cname": {},
"custom_404": false,
"html_url": "https://jiaxiangbu.github.io/test-gh/",
"source": {
"branch": "master",
"path": "/"
}
}
The README.md is valid, https://jiaxiangbu.github.io/test-gh/README.md.
> dir.create("docs")
> file.edit("docs/index.html")
> git2r::add(path = "docs/")
> git2r::commit(message = "add index.html")
[0fa6c7b] 2020-02-06: add index.html
> git2r::push(name = 'origin', refspec = "refs/heads/master", cred = git2r::cred_token())
生成 docs
71 审核成功
Thanks,
on its way to CRAN.
Best,
Martina Schmirl
72 发布 R CRAN 后续 workflow
发布博客 把 md 复制粘贴到正文,并且加上 R CRAN 的链接。
比如更新 README 模板,加入 R CRAN 的安装代码
如果是 Python 包,通过 setting 更新 desc
Update NEWS 14
release 产生 DOI 和 Citation 更新 R CRAN
不用慌,可以再修改的,只会生成这样一个 untagged 的链接 https://github.com/JiaxiangBU/rawKS/releases/tag/untagged-5dcfe009af815378d0b1 确保 zenodo 打开。
73 str_right_space
这个空格问题,转换成 unicode 然后合并到 archive 函数,先不要嵌套到函数中,DOT,分开开发。
74 devtools 2.2.2
submit_cran()
now returns a more informative error when the CRAN submission portal is downrelease()
now works if the package root is not in the working directory.
75 变量参数加上vars
knitr::include_graphics("figure/IMG_0276.png")
plot_mpg <- function(col_var, facet_var) {
ggplot(mpg) +
geom_point(aes(displ, hwy, col = .data[[col_var]])) +
facet_wrap(vars(.data[[facet_var]]))
}
plot_mpg(col_var = 'class', facet_var = 'drv')
plot_mpg <- function(.data, col_var, facet_var) {
ggplot(.data) +
geom_point(aes(displ, hwy, col = .data[[col_var]])) +
facet_wrap(vars(.data[[facet_var]]))
}
mpg %>%
plot_mpg(col_var = 'class', facet_var = 'drv')
76 查看包结构
## C:/Program Files/R/R-3.6.0/library/rhub
## +-- bin
## | +-- rhub-linux-docker.sh
## | \-- rhub-linux.sh
## +-- DESCRIPTION
## +-- doc
## | +-- index.html
## | +-- local-debugging.html
## | +-- local-debugging.R
## | +-- local-debugging.Rmd
## | +-- rhub.html
## | +-- rhub.R
## | \-- rhub.Rmd
## +-- help
## | +-- aliases.rds
## | +-- AnIndex
## | +-- figures
## | | \-- logo.png
## | +-- paths.rds
## | +-- rhub.rdb
## | \-- rhub.rdx
## +-- html
## | +-- 00Index.html
## | \-- R.css
## +-- INDEX
## +-- LICENSE
## +-- MD5
## +-- Meta
## | +-- features.rds
## | +-- hsearch.rds
## | +-- links.rds
## | +-- nsInfo.rds
## | +-- package.rds
## | +-- Rd.rds
## | \-- vignette.rds
## +-- NAMESPACE
## +-- NEWS.md
## \-- R
## +-- rhub
## +-- rhub.rdb
## \-- rhub.rdx
78 vignette 和 suggest
that packages used in the vignette need to be listed in DESCRIPTION (under Suggests if they’re only used in the vignette (Salmon 2020)
只在 vignette 使用的包,只需要放到 suggest。
附录
参考文献
Developed, RStudio. 2019. “Tidy Evaluation with Rlang Cheat Sheet.” 2019. https://resources.rstudio.com/rstudio-developed/tidyeval-2.
Dunnington, Dewey. 2020. “Best Practices for Programming with Ggplot2.” rstudio::conf 2020. 2020. https://resources.rstudio.com/rstudio-conf-2020/best-practices-for-programming-with-ggplot2-dewey-dunnington.
Salmon, Maëlle. 2020. “Optimal Workflows for Package Vignettes.” R-hub blog. 2020. https://blog.r-hub.io/2020/06/03/vignettes/.