mOna
mOna

Reputation: 2459

no visible global function definition and no visible binding for global variable

I've installed an R package, to create retweet cascades from a tweet object json file (here is the github page). Their code works with their sample data. Here is the 2 lines of code to create the cascades:

filepath <- system.file('extdata', 'tweets_anonymized.jsonl', package = 'evently')
cascades <- parse_raw_tweets_to_cascades(filepath, progress = F)

Note-1: the parse_raw_tweets_to_cascades function (in tweet.R file) create cascades from a given tweet object jsonl file.

PROBLEM: When I run it with my data (which seems to have the same structure), it correctly extract info (e.g., tweet_id, retweet_id, user_id, etc.) from data, but it doesn't create the cascades and shows this error:

Error in rep(1:nrow(index), cascade_sizes) : invalid 'times' argument

Apparently this error happens when the second argument (cascade_sizes) is either negative or Null or a vector of variables. I tried to print the cascade_size using print(paste("Mona Cascade sizes is", cascade_sizes)) which returns the following:

"Mona Cascade size is"

Note-2: After a specific line in this file (processed_tweets <- data.table::as.data.table(data.table::rbindlist(processed_tweets_batch))), I see the following issues:

I've read may similar posts, including the followings, but I couldn't fix my error yet:

UPDATE-1:

For example, I added the following in the tweet.R file (which was suggested in several answers):

#' @import utils 
utils::globalVariables(c("absolute_time", "start_ind", "end_ind"))

but I still get the same error.

UPDATE-2:

I also set those variables to NULL (as suggested here, but still I get the same error. I added the following line to the top of my function:

tweet_time <- end_ind <- start_ind <- absolute_time <- NULL

Upvotes: 1

Views: 705

Answers (1)

Winfried
Winfried

Reputation: 75

I was facing similar problems recently. The following things helped:

  • I added . <- var1 <- var2 <- NULL to my function. The trailing point is missing in your example.
  • I added #' @import data.table to the roxygen skeleton of my function and execute document(). This way the NAMESPACE file gets updated and data.table gets properly imported.

Upvotes: 1

Related Questions