简体   繁体   English

将 .db 文件导入 R

[英]Import .db file into R

I am trying to import a .db file using the code below, which is the same as the example with the package and it says can't find function.我正在尝试使用下面的代码导入一个 .db 文件,这与带有包的示例相同,它说找不到函数。 Anyone have any idea on how to import a .db file?任何人都知道如何导入 .db 文件?

library(ProjectTemplate)
db.reader('c3.db','/Users/xxx/Documents/c3.db','Data')

> db.reader('c3.db','/Users/xxx/Desktop/','Data')
Error: could not find function "db.reader"

I dont'use/have installed this package, however it seems this function is not exported and then not available to the user.我没有使用/已经安装了这个包,但是这个功能似乎没有导出,然后对用户不可用。 From the NAMESPACE fileNAMESPACE文件

# Generated by roxygen2 (4.0.0): do not edit by hand

export(cache)
export(cache.project)
export(create.project)
export(get.project)
export(load.project)
export(reload.project)
export(require.package)
export(run.project)
export(show.project)
export(stub.tests)
export(test.project)
export(translate.dcf)

After all, the example is毕竟,这个例子是

## Not run: db.reader('example.db', 'data/example.db', 'example')

The function is, however不过功能是

db.reader <- function(data.file, filename, variable.name)
{
  require.package('RSQLite')

  sqlite.driver <- dbDriver("SQLite")
  connection <- dbConnect(sqlite.driver,
                          dbname = filename)

  tables <- dbListTables(connection)
  for (table in tables)
  {
    message(paste('  Loading table:', table))

    data.parcel <- dbReadTable(connection,
                               table,
                               row.names = NULL)

    assign(clean.variable.name(table),
           data.parcel,
           envir = .TargetEnv)
  }

  disconnect.success <- dbDisconnect(connection)
  if (! disconnect.success)
  {
    warning(paste('Unable to disconnect from database:', filename))
  }
}

You could try to use it directly (from workspace), but best approach (IMHO) is可以尝试直接使用它(从工作区),但最好的方法(恕我直言)是

  • eventually to ask the maintainer (why can't it be ran, currently? Excluding an error in NAMESPACE generation, I think db.reader could be a placeholder at the moment) OR最终问维护者(为什么现在不能运行?排除NAMESPACE生成中的错误,我认为db.reader可能是一个占位符)或
  • if you used this package only for db file import, you could program your own RSQLite-based function (eg using this as a template)如果您仅将此包用于 db 文件导入,则可以编写自己的基于 RSQLite 的函数(例如,将其用作模板)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM