I have a package that scrapes data from the internet and displays its content based on the function call. But recently I got a message from CRAN that the data becomes stale when Binary build is installed (since the function was mentioned in utils.R
and it has downloaded while the build).
For the past few days, I've tried the following but no success:
- Global Variable using
<<-
but it generates a CRAN note and I also went through a few answers which advised against the approach Note:no visible binding for global variable
- Create a new environment and then add this downloaded object in that, but it never worked out since I couldn't access the object in other functions. Ref: Where to create package environment variables?
This is the current package files: https://github.com/amrrs/tiobeindexr/tree/master/R
Tried solution:
zzz.r
file:
.onLoad <- function (libname, pkgname)
{
assign("newEnv", new.env(hash = TRUE, parent = parent.frame()))
newEnv$.all_tablesx789 <- rvest::html_table(xml2::read_html('https://www.tiobe.com/tiobe-index/'))
}
one of the functions in the core code.
hall_of_fame <- function() {
#check_data()
#.GlobalEnv$.all_tablesx789 <- check_data()
newEnv$.all_tablesx789[[4]]
}
The package builds fine, but the object is not found. Error below:
Error in hall_of_fame() : object 'newEnv' not found
I've only a couple of days to save my package on CRAN and I hope I've provided enough data from saving this question being downloaded.
Thanks!