将.db文件导入R [英] Import .db file into R

查看:20764
本文介绍了将.db文件导入R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用下面的代码导入.db文件,这与包中的示例相同,并且它说找不到函数。任何人都知道如何导入.db文件?

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

> db.reader('c3.db','/ Users / xxx / Desktop /','Data')
错误:找不到函数db.reader


解决方案

我不使用/已安装此软件包,但似乎此功能未导出然后无法使用给用户。来自 NAMESPACE 文件

 #由roxygen2(4.0.0)生成:不要手动编辑

export(缓存)
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)

毕竟,示例是

  ##未运行:db.reader('example.db ','data / example.db','example')

该函数是

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

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

表< - dbListTables(连接)
f或(表格中的表格)
{
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(连接)
if(! disconnect.success)
{
警告(粘贴('无法与数据库断开:',文件名))
}
}

可以尝试直接使用它(来自工作区),但最佳方法(恕我直言)是


  • 最终要求维护者(为什么不能在当前运行?排除 NAMESPACE中的错误代,我认为 db.reader 目前可能是占位符或者

  • 如果您仅将此包用于db文件导入,则可以
    编写自己的基于RSQLite的函数(例如,将其用作模板)


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. Anyone have any idea on how to import a .db file?

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 file

# 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
  • 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文件导入R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆