【问题标题】:R SQLite issue from Python来自 Python 的 R SQLite 问题
【发布时间】:2021-02-24 13:43:12
【问题描述】:

所以我正在尝试从 python 运行 Rscript,rscript 正在使用 Rsqlite

这里是python调用

subprocess.call(['C:\\Program Files\\R\\R-4.0.1\\bin\\Rscript', 'C:\\Users\\A\\Documents\\sql\\master\\test.R'])

这里是 test.R 脚本的内容

test <- function(){
  library(RSQLite)
  
  db <- dbConnect(SQLite(), "A.db")
  
  tblist <- dbListTables(db)
  print("we made it in")
  print(tblist)
  
}

test()

当我在 Rstudio 中运行它时,我会得到表格列表

当我在 python 中运行它时,我得到以下内容

[1] "we made it in"
character(0)

这意味着我没有通过 shell 正确访问 A.db 文件

对为什么会出现这种情况有什么想法吗?

【问题讨论】:

    标签: python r python-3.x rsqlite


    【解决方案1】:

    答案原来如此简单

    setwd("C:\Users\A\Documents\sql\master\")
    

    被添加到脚本的顶部;当我添加 getwd() 时,它是从 python wd 运行的,现在看起来很明显

    【讨论】:

      猜你喜欢
      • 2018-12-06
      • 2022-11-24
      • 2021-01-08
      • 2015-10-07
      • 2018-02-14
      • 1970-01-01
      • 2010-10-05
      • 2021-08-06
      • 1970-01-01
      相关资源
      最近更新 更多