我有一个文本文件(比如说维度.txt)其中包含某些数据,
我想在 R 中编写一个函数,将该文本文件转换为 pdf 文件。
在我来到这里之前我用谷歌搜索了很多。有很多地方人们询问如何将 pdf 文件转换为文本,而不是反之亦然。
这是我的代码:
FunctionFun <- function(.csv)
{
sink('Dimension.txt')
csv <- read.csv(.csv)
dimValue <- dim(csv)
print("The dimension of the dataset is:")
print(dimValue)
return(dimValue)
sink('Dimension.txt', append=TRUE)
}
When I run FunctionFun("tips.csv")
, I get a text file as an output, which looks like:
现在,我的任务是编写一个单独的函数来转换维度.txt to 维度.pdf.
感谢您的帮助。
Thanks.
您可以使用执行以下操作rmarkdown
require(rmarkdown)
my_text <- readLines("YOUR PATH")
cat(my_text, sep=" \n", file = "my_text.Rmd")
render("my_text.Rmd", pdf_document())
file.remove("my_text.Rmd") #cleanup
Which gives you a PDF document named my_text.pdf
that looks as follows:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)