调用函数而不复制到脚本窗口

时间:2016-07-15 12:37:22

标签: r function

我的R安装的默认库是 ERROR [metrics-graphite-reporter-1-thread-1] 2016-07-13 08:21:23,580 ScheduledReporter.java:119 - RuntimeException thrown from GraphiteReporter#report. Exception was suppressed. java.lang.IllegalStateException: Unable to compute ceiling for max when histogram overflowed at org.apache.cassandra.utils.EstimatedHistogram.rawMean(EstimatedHistogram.java:231) ~[apache-cassandra-3.0.7.jar:3.0.7] at org.apache.cassandra.metrics.EstimatedHistogramReservoir$HistogramSnapshot.getMean(EstimatedHistogramReservoir.java:103) ~[apache-cassandra-3.0.7.jar:3.0.7] at com.codahale.metrics.graphite.GraphiteReporter.reportHistogram(GraphiteReporter.java:265) ~[metrics-graphite-3.1.2.jar:3.1.2] at com.codahale.metrics.graphite.GraphiteReporter.report(GraphiteReporter.java:179) ~[metrics-graphite-3.1.2.jar:3.1.2] at com.codahale.metrics.ScheduledReporter.report(ScheduledReporter.java:162) ~[metrics-core-3.1.0.jar:3.1.0] at com.codahale.metrics.ScheduledReporter$1.run(ScheduledReporter.java:117) ~[metrics-core-3.1.0.jar:3.1.0] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_91] at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [na:1.8.0_91] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_91] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_91] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_91] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_91] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91]

我还将.txt扩展名的功能保存在第二个文件夹中 C:\Users\mmstat\Documents\R\win-library\3.3\

我的问题是,我不知道如何告诉R我的功能库' S库'所以我不必在我的脚本窗口中复制并粘贴所需函数的代码,然后执行它。

我该怎么做?

2 个答案:

答案 0 :(得分:2)

只是给出最简单的基础R答案:

fList <- list.files(path="c:/S library/",pattern="*.txt")
lapply(fList,source)

答案 1 :(得分:1)

注意:我没有窗口,因此路径可能需要一些编辑才能在您自己的系统上正常工作。

注意2:您可能需要将文件的扩展名从.txt更改为.R

如果您想创建/使用它作为包,您可以尝试modules包。它是在考虑python用户的情况下构建的。

如果你经常使用这些函数,我建议你也可以在.Rprofile中添加一个变量(对于基于Unix的系统,它通常是:〜/ .Rprofile,不知道windows)

import.path='c:/S library/' #Based on Ben Bolker recommendation

如果您不想或不能修改您的个人资料,您也可以在R内部进行修改(但您需要每次都这样做)。

然后在R:

#only the first time and if you want to update later on.
require(devtools) ## you will need to install it if you don't have it already
devtools::install_github('klmr/modules') 

然后每当你想要使用它时,它将如下所示:

library(modules)
options(import.path="c:\\S library\\")
Slib=import('nameOftextFile')#example myFun

and then you can use it:

foo=Slib$myFun(arg1,arg2,)

请阅读documentation以获得更好的解释。