加入r径向外壳命令中的分隔符

发布于 2025-02-01 12:02:57 字数 743 浏览 5 评论 0原文

function的shell命令功能作为预处理步骤

foods.txt:

ID|FOOD
100000853384|Cheese
100003735682|Potato
100006367485|Apple
100007267644|Beef

food_types.txt:

ID|TYPE
100000853384|Fat
100003735682|Carbohydrate
100006367485|Fruit
100007267644|Protein

library(data.table)
foods <- fread(cmd = paste("join -t '|' food_types.txt foods.txt"))

我有两个.txt文件,我想使用r data.table fread 它返回一个错误,说明

''' is not recognized as an internal or external command,
operable program or batch file.

,如果我将定界符更改为逗号,并且使用

foods <- fread(cmd = paste("join -t ',' food_types.txt foods.txt"))

如何使Join与管道定界符配合使用?我在Windows 10 Pro上使用R 4.1.3版。

I have two .txt files that I want to join using the R data.table fread function's shell command feature as a pre-processing step before importing into R. The two files are:

foods.txt:

ID|FOOD
100000853384|Cheese
100003735682|Potato
100006367485|Apple
100007267644|Beef

food_types.txt:

ID|TYPE
100000853384|Fat
100003735682|Carbohydrate
100006367485|Fruit
100007267644|Protein

I tried this code

library(data.table)
foods <- fread(cmd = paste("join -t '|' food_types.txt foods.txt"))

But it returns an error saying

''' is not recognized as an internal or external command,
operable program or batch file.

However, the join works properly if I change the delimiter to a comma and use

foods <- fread(cmd = paste("join -t ',' food_types.txt foods.txt"))

How can I get the join to work with the pipe delimiter? I am using R version 4.1.3 on Windows 10 Pro.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等待我真够勒 2025-02-08 12:02:57

您可以切换双人行情吗?

fread(cmd = paste('join -t "|" food_types.txt foods.txt'))

输出:

             ID         TYPE\r   FOOD
1: 100000853384          Fat\r Cheese
2: 100003735682 Carbohydrate\r Potato
3: 100006367485        Fruit\r  Apple
4: 100007267644        Protein   Beef

Can you switch the double and single quotes?

fread(cmd = paste('join -t "|" food_types.txt foods.txt'))

Output:

             ID         TYPE\r   FOOD
1: 100000853384          Fat\r Cheese
2: 100003735682 Carbohydrate\r Potato
3: 100006367485        Fruit\r  Apple
4: 100007267644        Protein   Beef
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文