且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将.db文件导入R

更新时间:2022-10-14 20:25:12

我不使用/已安装此软件包,但似乎此功能未导出然后无法使用给用户。来自 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)