gpt4 book ai didi

r - 使用 org-mode 构建分析

转载 作者:行者123 更新时间:2023-12-03 11:02:36 25 4
gpt4 key购买 nike

我正在尝试更好地为我的项目使用 org-mode。我认为识字编程特别适用于数据分析领域,而 org-mode 让我们可以做一些非常棒的识字编程。

我想你们中的大多数人都会同意我的观点,即编写分析的工作流程与大多数其他类型的编程不同。我不只是编写程序,我探索数据。而且,虽然其中许多探索都是死胡同,但我不想完全删除/忽略它们。我只是不想每次执行 org 文件时都重新运行它们。我也倾向于找到或开发我想放入分析模板中的有用代码块,但其中一些 block 与每个项目都不相关,我想知道如何让 org-mode 忽略这些执行整个缓冲区时的 block 。这是一个简化的例子。

* Import
- I want org-mode to ignore import-sql.
#+srcname: import-data
#+begin_src R :exports none :noweb yes
<<import-csv>>
#+end_src

#+srcname: import-csv
#+begin_src R :exports none
data <- read.csv("foo-clean.csv")
#+end_src

#+srcname: import-sql
#+begin_src R :exports none
library(RSQLite)
blah blah blah
#+end_src

* Clean
- This is run on foo.csv, producing foo-clean.csv
- Fixes the mess of -9 and -13 to NA for my sanity.
- This only needs to be run once, and after that, reference.
- How can I tell org-mode to skip this?
#+srcname: clean-csv
#+begin_src sh :exports none
sed .....
#+end_src

* Explore

** Explore by a factor (1)
- Dead end. Did not pan out. Ignore.
- Produces a couple of charts showing there is not interaction.
#+srcname: explore-by-a-factor-1
#+begin_src R :exports none :noweb yes
#+end_src

** Explore by a factor (2)
- A useful exploration that I will reference later in a report.
- Produces a couple of charts showing the interaction of my variables.
#+srcname: explore-by-a-factor-2
#+begin_src R :exports none :noweb yes
#+end_src

我希望能够使用 org-babel-execute-buffer 并让 org-mode 以某种方式知道跳过代码块 import-sql、clean-csv 和 explore-by-a-factor-1。我希望它们在 org 文件中,因为它们与项目相关。毕竟,明天有人可能想知道为什么我如此确定 explore-by-a-factor-1 没有用。我想保留该代码,这样我就可以完成绘图或分析或其他任何事情并继续进行,但不是每次我重新运行所有内容时都运行它,因为没有理由运行它。与 clean-csv 一样。我想要它,记录我对数据做了什么(以及为什么),但我不想每次都重新运行它。我将只导入 foo-clean.csv。

我在谷歌上搜索并阅读了一堆 org-mode 邮件列表文件,我能够找到一些想法,但不是我想要的。导出文件时,EXPORT_SELECT_TAGS、EXPORT_EXCLUDE_TAGS 很棒。在创建实际的源文件时, :tangle header 效果很好。我不想做这两件事。我只想执行缓冲区。我希望能够以类似的方式定义要执行或忽略的代码块。我想我想找到一种方法来拥有一个 org 变量,例如:

EXECUTE_SELECT_TAGS

这样我就可以简单地标记我的各种代码块并完成它。如果我可以然后只使用带有特定标签的源 block 来运行该文件,那就更好了。我找不到这样做的方法,我想我会在询问/乞求 org-mode 中的新功能之前先询问一下。

最佳答案

我想通了。从组织手册:

:eval header 参数可用于限制特定代码块的评估。 :eval 接受两个参数“never”和“query”。 :eval never 将确保永远不会评估代码块,这对于防止评估危险代码块很有用。 :eval 查询将需要对代码块的每次执行进行查询,而不管 org-confirm-babel-evaluate 变量的值如何。

所以你只需要添加

:eval 从不

到您不想执行的 block 的标题,瞧!

关于r - 使用 org-mode 构建分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4305497/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com