在 R 中读取 .rdb 文件时出现问题

问题描述

我正在尝试读取 .rdb 文件以收集其中包含的 R 代码。但是,使用以下代码时出现以下错误,请参阅:

> setwd("C:\\Users\\")
> lazyLoad(filebase="treeTaper",envir=parent.frame())
NULL
> 

该消息似乎警告说没有可以读取的文件,但是,有文件在这种情况下,我如何读取这个文件,然后收集必要的信息?

在下面提供的链接中是文件 文件链接https://drive.google.com/drive/folders/1JzBuH63LiaZNeJDzYvKVWk2utWFJuLdk?usp=sharing

注意:目前,treeTaper 包已经失效,是这个原因吗?

install.packages("treeTaper")
Installing package into ‘C:/Users/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
Warning in install.packages :
  package ‘treeTaper’ is not available (for R version 4.0.2)

解决方法

lazyLoad 函数主要通过副作用起作用,这对我来说意味着您不应该依赖(也不应该被)NULL 输出。

例如

ls()
# character(0)
lazyLoad("c:/Users/r2/R/win-library/4.0/yaml/help/yaml",envir = .GlobalEnv)
# NULL
ls()
# [1] "as.yaml"    "read_yaml"  "write_yaml" "yaml.load" 
as.yaml
# \title{ Convert an R object into a YAML string }\name{as.yaml}\alias{as.yaml}\keyword{ data }\keyword{ manip }\description{
#   Convert an R object into a YAML string
# }\usage{
#   as.yaml(x,line.sep = c("\n","\r\n","\r"),indent = 2,omap = FALSE,#           column.major = TRUE,unicode = TRUE,precision = getOption('digits'),#           indent.mapping.sequence = FALSE,handlers = NULL)
# }.......

如果您希望对象在特定位置可用,那么最好控制它的位置。 (您正在使用的 envir=parent.frame() 似乎会用这些帮助文档的承诺对象污染调用环境。)

e <- new.env(parent = emptyenv())
lazyLoad("c:/Users/r2/R/win-library/4.0/yaml/help/yaml",envir = e)
# NULL
ls(e)
# [1] "as.yaml"    "read_yaml"  "write_yaml" "yaml.load" 
e$as.yaml
# \title{ Convert an R object into a YAML string }\name{as.yaml}\alias{as.yaml}\keyword{ data }\keyword{ manip }\description{
#   Convert an R object into a YAML string
# }\usage{
#   as.yaml(x,handlers = NULL)
# }......