管道输出到文件到功能

时间:2023-02-04 14:04:32

I have a function, call it a(), that writes something to a file and another function, call it b() that reads something from a file. I would like to pipe the output of a() and pipe it into b() without a file ever actually being created. Is this possible?

我有一个函数,称之为a(),将某些内容写入文件和另一个函数,将其称为b(),从文件中读取内容。我想管道a()的输出并将其传递到b()而不用实际创建的文件。这可能吗?

(for the curious: a() is aws.s3::save_object(), which saves an object from an S3 bucket to disk and b() is feather::read_feather(), which reads in a feather file into a tibble.)

(对于好奇:a()是aws.s3 :: save_object(),它将一个对象从S3存储桶保存到磁盘,b()是一个羽毛:: read_feather(),它将一个羽毛文件读入一个tibble。 )

1 个解决方案

#1


1  

The return value of save_object() is a file string containing the path to the saved file, so you can just nest your function calls:

save_object()的返回值是一个包含保存文件路径的文件字符串,因此您可以嵌套函数调用:

library("aws.s3")
library("feather")
read_feather(save_object("objectkey", "bucket"))

If feather is capable of reading from a connection (seems like it isn't, but if it could), you can skip the disk I/O and use get_object() instead:

如果feather能够从连接中读取(似乎不是,但如果可以),则可以跳过磁盘I / O并使用get_object()代替:

read_feather(rawConnection(get_object("objectkey", "bucket")))

(Note: I'm the maintainer of the aws.s3 package.)

(注意:我是aws.s3包的维护者。)

#1


1  

The return value of save_object() is a file string containing the path to the saved file, so you can just nest your function calls:

save_object()的返回值是一个包含保存文件路径的文件字符串,因此您可以嵌套函数调用:

library("aws.s3")
library("feather")
read_feather(save_object("objectkey", "bucket"))

If feather is capable of reading from a connection (seems like it isn't, but if it could), you can skip the disk I/O and use get_object() instead:

如果feather能够从连接中读取(似乎不是,但如果可以),则可以跳过磁盘I / O并使用get_object()代替:

read_feather(rawConnection(get_object("objectkey", "bucket")))

(Note: I'm the maintainer of the aws.s3 package.)

(注意:我是aws.s3包的维护者。)