我正在开发一个R应用程序并想出一个解决方法,通过向项目根目录添加一个文件来集成testthat(它通常需要你的项目成为一个包)DESCRIPTION.
我从同事那里获得了这种方法,并设法让它像这样工作.
问题是,当我尝试测试任何东西(甚至是空的测试文件)时,我收到此错误:
Error in x[[method]](...) : attempt to apply non-function
Calls: <Anonymous> ... <Anonymous> -> o_apply -> lapply -> FUN -> <Anonymous>
Execution halted
Run Code Online (Sandbox Code Playgroud)
我知道的是,这似乎只有在MacOS.我的同事仍可在Windows上运行此应用程序而不会出现问题.
这有什么用处?
用于重现此错误的MCVE将是:
创建DESCRIPTION包含内容的最小文件:
Package: testpckg
Run Code Online (Sandbox Code Playgroud)将testthat添加到您的项目中:
usethis::use_testthat()
usethis::use_test("foo")
Run Code Online (Sandbox Code Playgroud)bar.Rtest-foo.R,源栏:source("bar.R")RStudio版本1.1.447,R版本3.4.4,Mac OS X 10_13_4
我需要声明一个变量,如下所示:
var cell
if cond {
cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as? CustomCell1
}
else {
cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as? CustomCell2
}
Run Code Online (Sandbox Code Playgroud)
这里的问题是我收到错误Type annotation missing in pattern。
我应该声明什么类型的变量或者是否有解决此问题的方法?
我有以下字典:
let dict = ["key1": "v1", "key2": "v1", "key3": "v2"]
Run Code Online (Sandbox Code Playgroud)
我想交换键的值,以便结果是:
result = ["v1": ["key1", "key2"], "v2": ["key3"]]
Run Code Online (Sandbox Code Playgroud)
在不使用for循环的情况下如何做到这一点(即更优雅)?
将已定义数组中的所有值设置为trueor的最优雅方法是什么false?我正在考虑不使用for循环。
我目前正在使用仅使用TRUE值重新初始化数组的想法,我很好奇是否存在更好的方法。