包测试时运行期望的输入



在测试包的函数时,我得到了这个。out

* installing *source* package 'trib' ...
** R
Error in parse(outFile) : 
C:R/trib.Rcheck/00_pkg_src/trib/R/tribF.R:48:27: unexpected input
47: 
48:     CF[i]<-mean(All[[i]]$μ
                          ^
ERROR: unable to collate and parse R files for package 'trib'

问题是μ (mu)符号。我所有的文件都有它,我可以使用这些函数。我也想在包中使用这个功能,这样我的同事就可以使用csv文件了。

功能在

下面
trib.CoF <- function(x) { #gets file name length input returns coeficient of friction in bar plot generates global var CF
namesAll<-trib.names(x)
CF <<- vector(mode = "numeric")     #generate vector for values
for (i in 1:l_All){
CF[i]<-mean(All[[i]]$μ)}             #get all coefficient of friction data into CF
names(CF)<-namesAll
barplot(CF,main="Average Friction Coefficient",
      xlab="Samples",ylab="μ",xlim=c(0,length(CF)*1.25+1), ylim = c(0,1.2*max(CF)),col=c(1:l_All))    #generate bar plot
legend("topright", legend=signif(CF,6),col=c(1:l_All),pch=16,cex=0.8)                                 #add legends
}

这个问题看起来很像,但是我找不到解决方法

我找到了解决我自己问题的方法。这是一种变通方法,但取决于表结构。假设我的表是这样的

Time    Distance     Laps      µ          FrictionForce
0,100   0           0,00000   0,18478       0,55435

µ是第四列。所以不用它的名字,我只用它的编号。我将修改

CF[i]<-mean(All[[i]]$μ)}             #get all coefficient of friction data into CF

CF[i]<-mean(All[[i]][[4]])} #get all coefficient of friction data into CF

这将消除非ASCII字符错误,所以我可以编译成一个包。我可能不得不为输入结构写一个表检查函数,但在手册中描述它并给出一个数据集应该足够了。

最新更新