我写了一个R包,用于整合电子病历.我想我已经在DESCRIPTION文件中正确添加了导入和依赖项,并通过roxygen2记录了所有内容,但是我的三个函数(都在同一个文件中)我在运行devtools :: check("."时收到此警告. ):
* checking for missing documentation entries ... WARNING
Undocumented code objects:
'add_to_database' 'database' 'import_CPRD_data'
All user-level objects in a package should have documentation entries.
Run Code Online (Sandbox Code Playgroud)
我想我已经记录了这些与我所有其他功能相同的方式.以下是roxygen2文档中的一个违规函数:
#' Wrapper for dbconnect
#'
#' Connects to a SQLite database or creates one if it does not already exist
#'
#' If the '.sqlite' file extension is ommited from the dbname argument it is automatically added.
#'
#' @export
#'
#' @param dbname character name path to database file
#' …
Run Code Online (Sandbox Code Playgroud) 我对来自R和Python的CL相当新.
我想定义一个函数,我可以传递任意数量的参数,并且如果我想要默认值中的不同值,也可以设置我可以设置的默认值的关键字.
在RI中可以这样做:
foo <- function(..., a = 1, b = 2){
list(a = a, b = b, ...)
}
foo(1, 2, 3)
foo(1, 2, 3, a = 2)
foo(b = 10, 1, 2, 3)
Run Code Online (Sandbox Code Playgroud)
在PCL中,它表示你可以组合使用&key和&rest参数但是如果我尝试类似的话,它就不会像我期望的那样工作
(defun foo (&rest rest &key (a 1) (b 2))
(list rest a b))
Run Code Online (Sandbox Code Playgroud)
在这里,如果我指定除了两个关键字args以外的任何内容,我会收到一个未知和密钥错误:
(foo :a 100 12 3)
>> unknown &KEY argument: 12
Run Code Online (Sandbox Code Playgroud)
我想要的是类似的功能:
(defun bar (&optional (a 1) (b 2) &rest rest)
(list rest a b))
(bar 5 4 1 …
Run Code Online (Sandbox Code Playgroud) 我一直在使用clojure,但我不熟悉twitter-api(https://github.com/adamwynne/twitter-api)所基于的async io .
我想收集与给定关键字集匹配的所有推文.例如,所有与"玛丽玫瑰"相匹配的东西(现在在英国呈现趋势).制作流媒体电话的文档说要做以下事情:
(ns mynamespace
(:use
[twitter.oauth]
[twitter.callbacks]
[twitter.callbacks.handlers]
[twitter.api.streaming])
(:require
[clojure.data.json :as json]
[http.async.client :as ac]
[clojure.java.io :as io])
(:import
(twitter.callbacks.protocols AsyncStreamingCallback)))
(def my-creds (make-oauth-creds *app-consumer-key*
*app-consumer-secret*
*user-access-token*
*user-access-token-secret*))
; supply a callback that only prints the text of the status
(def ^:dynamic
*custom-streaming-callback*
(AsyncStreamingCallback. (comp println #(:text %) json/read-json #(str %2))
(comp println response-return-everything)
exception-print))
(statuses-filter :params {:track "mary rose"}
:oauth-creds my-creds
:callbacks *custom-streaming-callback*)
Run Code Online (Sandbox Code Playgroud)
如果我然后做类似的事情:
(def mary (statuses-filter :params {:track "mary rose"}
:oauth-creds my-creds
:callbacks …
Run Code Online (Sandbox Code Playgroud) 我想从它们的组件构建 R 函数,如下所示:
testfn <- function(..., expression){
args <- substitute(alist(...))
body <- substitute(expression)
eval(call("function", as.pairlist(eval(args)), body), parent.frame())
}
Run Code Online (Sandbox Code Playgroud)
如果有默认值,这可以正常工作:
testfn(x = 4, y = 5, expression = {
y <- y + 2
x + y
})
=>
function (x = 4, y = 5)
{
y <- y + 2
x + y
}
Run Code Online (Sandbox Code Playgroud)
但如果一个或多个参数没有默认参数,它将不起作用:
testfn(x = 4, y, expression = {
y <- y + 2
x + y
})
=>
Error in eval(expr, …
Run Code Online (Sandbox Code Playgroud)