Twitter streaming error, 'invalid length argument'? - r

The code is as follows;
Supplier_List <- data.frame(companies = c("company1","company2","company3"))
Streamed_Tweets <- purrr::map_df(Supplier_List$companies, ~{
search_tweets2(.x, retryonratelimit = TRUE,include_rts=FALSE,lang="en")
#Sys.sleep(5)
}, .id = 'id')
The error that comes up is
Error in vector("list", ntimes) : invalid 'length' argument
Could anyone please help?

Related

Error when using write_as_csv() in rtweet package

When I use the write_as_csv() from the rtweet package, I get the following error:
Twitterstorians_hashtag <- search_tweets(
q="#Twitterstorians",
n = 100,
type = "recent",
include_rts = TRUE,
parse = TRUE,
)
save_as_csv(Twitterstorians_hashtag, "Twitterstorians_hashtag.csv", prepend_ids
= TRUE, na = "", fileEncoding = "UTF-8")
Error in utils::write.table(x, file_name, row.names = FALSE, na = na, :
unimplemented type 'list' in 'EncodeElement'
In addition: Warning message:
In flatten(x) : data frame still contains recursive columns!
If I try to use flatten(), I get the following error:
Error in flatten_int(x) : Not compatible with STRSXP: [type=list].
I'm not sure how to fix these errors? Any suggestions would be much appreciated

Error in parse(text = x, keep.source = FALSE) : <text>:1:15: unexpected symbol 1: ID ~ 0+Offset Length

I would like to ask you for help. I am trying to perform MICE imputation of missing values in my dataset. Here is part of the code:
imputed_Data <- mice(data, m=5, maxit = 10, method = "PMM", seed = 200)
Unfortunately, this code returns the following error:
Error in parse(text = x, keep.source = FALSE) :
<text>:1:15: unexpected symbol
1: ID ~ 0+Offset Length
^
Does anybody knows where the mistake is? "ID" and "Offset Length" are variables in my dataset.
Thank you,
Blanka

Error when using qualtRics::fetch_survey() with partial

I'm getting the following error message when using qualtRics::fetch_survey function together with purrr::partial:
library(tidyverse)
library(qualtRics)
fetch_new_survey <- partial(fetch_survey,
force_request = TRUE)
fetch_new_survey(some_survey_id)
Error in vapply(match.call(), deparse, "character") : `values must be
length 1, but FUN(X[[1]]) result is length 68
Am I using partial incorrectly, or is there something else going on here?

Error when performing expand.grid() on dataframe

I was preforming expand.grid() on subdb, how to tackle this?
full <- with(subdb, expand.grid(sort(unique(UserId), sort(unique(ProductId))))
Error in eval(substitute(expr), data, enclos = parent.frame()) :
invalid 'envir' argument of type 'character'
Why I am getting this error?
subdb is a data frame holding 'UserId', 'ProductId', and 'Score'.
You miss a parenthesis in the first call to sort(), namely it should be sort(unique(UserId)) not sort(unique(UserId).
For example, the following works for me:
subdb <- data.frame("UserId" = sample(1:10, 200, replace = TRUE),
"ProductId" = sample(LETTERS[1:8], 200, replace = TRUE))
full <- with(subdb, expand.grid(sort(unique(UserId)),
sort(unique(ProductId))))
full

Trapping error in R

A very basic quesiton. But i am not able to apply this to my code. Hence seeking help here
I am getting an error mentioned below while running this R code
knn.pred <- knn(tdm.stack.nl_train, tdm.stack.nl_Test, tdm.cand_train, prob = TRUE)
> Error in knn(tdm.stack.nl_train, tdm.stack.nl_Test, tdm.cand_train, prob = TRUE) :
> dims of 'test' and 'train' differ.
I want to print the error message as given below. However I could not achieve this. I am not good in writing functions yet.. Please help.
out <- tryCatch( when error = {print('New words seen in testing data')})
It's better and easier to use try:
knn.pred <- try(knn(tdm.stack.nl_train, tdm.stack.nl_Test, tdm.cand_train, prob = TRUE))
if (inherits(knn.pred, "try-error") { # error management
print('New words seen in testing data')
}
You could do:
tryCatch(knn.pred <- knn(tdm.stack.nl_train, tdm.stack.nl_Test, tdm.cand_train, prob = TRUE),
error = function(e) {
stop('New words seen in testing data')
})
This shows up as:
tryCatch(knn.pred <- knn(tdm.stack.nl_train, tdm.stack.nl_Test, tdm.cand_train, prob = TRUE),
error = function(e) {
stop('New words seen in testing data')
})
Error in value[[3L]](cond) : New words seen in testing data

Resources