小编Bun*_*nty的帖子

在 Excel 中运行 R 脚本

关于如何执行此操作的信息并不多。我试着在网上研究了一个博客,并在 VBA 中实现了以下代码(带有 R 文件的路径):-

Sub RunRscript()
    'runs an external R code through Shell
    'The location of the RScript is 'C:\R_code'
    'The script name is 'hello.R'

    Dim shell As Object
    Set shell = VBA.CreateObject("WScript.Shell")
    Dim waitTillComplete As Boolean: waitTillComplete = True
    Dim style As Integer: style = 1
    Dim errorCode As Integer
    Dim path As String
    path = "RScript C:\R_code\hello.R"
    errorCode = shell.Run(path, style, waitTillComplete)
End Sub
Run Code Online (Sandbox Code Playgroud)

来源

但是,当我在 Excel 中运行宏时,它基本上什么都不做——只是在 RStudio 中打开脚本。我没有收到任何错误,但它没有给出任何输出 - 只是在 Rstudio 中打开 R 脚本。我究竟做错了什么?

另外,如果我需要在 …

excel vba r rexcel

5
推荐指数
1
解决办法
1万
查看次数

R Script pdf 使用 pdftools

我正在使用 pdftools 将 pdf 转换为 excel。我想提取表格值。下面的代码工作得很好,但它将所有内容粘贴到行中(我的意思是这些值没有在不同的列中分开 - 我唯一想要的是表格,因为它在 pdf 中(数据和值) . . . 有人可以帮忙写代码吗?也许我们需要一个分隔符?我希望得到一些帮助!下面的 3 张图片:- Excel 输出,预期的 Excel 输出和我正在使用的 PDF。

library(pdftools)
tx<-pdf_text("Path")
tx2<-strsplit(tx,"\n")
library(xlsx)
write.xlsx(tx2,file="ds.xlsx")
Run Code Online (Sandbox Code Playgroud)

pdf excel r

0
推荐指数
1
解决办法
7944
查看次数

标签 统计

excel ×2

r ×2

pdf ×1

rexcel ×1

vba ×1