源脚本或脚本的某些行

时间:2022-12-06 09:11:32

I have multiple R scripts for different models and I need to make it easily accessible for other people to use. So I would like to have one script in which only contains sources to run the other scripts without people having to search through many files to find the right one. some of the scripts have more than one model in so if possible I would like to source only specific blocks of lines from those scripts.

对于不同的模型,我有多个R脚本,我需要使它易于为其他人使用。因此,我希望有一个脚本,其中只包含可以运行其他脚本的源代码,而不需要人们搜索许多文件来找到正确的文件。有些脚本中有多个模型,所以如果可能的话,我只希望从这些脚本中找到特定的行块。

For example to find the accuracy of ARIMA in different ways I have to run the following different scripts in turn;

例如,为了以不同的方式找到ARIMA的准确性,我必须依次运行以下不同的脚本;

  • Read data
  • 读取数据
  • Arima
  • 华宇电脑
  • Accuracy of in-sample
  • 分类的准确性
  • Accuracy out Read data
  • 准确读取数据
  • Accuracy of out forced param
  • 输出的精度。
  • Accuracy out sample
  • 准确性出样品

The amount of different scripts causes the risk of an error to be higher. especially as within 3 of those scripts is 5 other models which if running myself I would just highlight the specific model I'm wanting to use and run, but for other people that may be more confusing.

不同脚本的数量会导致错误的风险更高。特别是在这3个脚本中有5个其他模型如果我自己运行的话,我只会强调我想要使用和运行的特定模型,但是对于其他人来说,这可能更令人困惑。

I know that I have to use source() to get the scripts to run but im stuck as to how to source only certain parts of the script and the correct way to source

我知道我必须使用source()来让脚本运行,但是我无法确定如何只对脚本的某些部分进行源代码,以及如何正确地进行源代码

2 个解决方案

#1


1  

You could make one code that automates the whole thing and then use knitr to create a word, or pdf document of the whole thing for other people to read easily?

你可以编写一个代码来自动化整个事情,然后使用knitr来创建一个单词,或者整个事情的pdf文档,让其他人轻松阅读?

#2


3  

Rather than trying to source parts of scripts, move these bits of code into functions, and then just call the functions you need.

与其尝试编写脚本的各个部分,不如将这些代码移动到函数中,然后调用所需的函数。

Start by searching around for how to write R functions

首先搜索一下如何写R函数

You can put all your functions into a single file, source it, and then make your recipes of functions with orders for others.

您可以将所有的函数放在一个文件中,并对其进行源代码处理,然后根据其他函数的订单制作函数食谱。

#1


1  

You could make one code that automates the whole thing and then use knitr to create a word, or pdf document of the whole thing for other people to read easily?

你可以编写一个代码来自动化整个事情,然后使用knitr来创建一个单词,或者整个事情的pdf文档,让其他人轻松阅读?

#2


3  

Rather than trying to source parts of scripts, move these bits of code into functions, and then just call the functions you need.

与其尝试编写脚本的各个部分,不如将这些代码移动到函数中,然后调用所需的函数。

Start by searching around for how to write R functions

首先搜索一下如何写R函数

You can put all your functions into a single file, source it, and then make your recipes of functions with orders for others.

您可以将所有的函数放在一个文件中,并对其进行源代码处理,然后根据其他函数的订单制作函数食谱。