I had this working completely fine and changed nothing, but when I ran it again I got the error code:
Error in toJSON(json_data, pretty = TRUE) :
unused argument (pretty = TRUE)
in reference to the line below. When I print(json_data) everything prints out fine so I know it has nothing to do with the data. I'm pretty lost, any ideas? I reinstalled all of the packages I am using (jsonlite, rjson, etc.) and as far as my research shows pretty = TRUE should be working just fine. My code is below:
x <- toJSON(json_data, pretty = TRUE)
Here is an example of the data:
$`#context`
[1] "context.jsonld"
$archiveType
[1] "Marine sediment"
$dataSetName
[1] "2005-804.devernal.2013"
$pub
$pub[[1]]
$pub[[1]]$pubYear
[1] "2013"
Related
This is an example code snippet:
Problematic Code:
```{r}
ratings <- df %>%
dplyr::group_by(rating) %>%
dplyr::summarise(
compound = mean(compound),
neg = mean(neg),
neu = mean(neu),
pos = mean(pos),
)
View(ratings)
```
This is the error I get:
Error message
r$> ratings <- df %>%
dplyr::group_by(rating) %>%
dplyr::summarise(
compound = mean(compound),
neg = mean(neg),
neu = mean(neu),
Error: unexpected '}' in:
" neu = mean(neu),
}"
r$> pos = mean(pos)
)
Error: unexpected ')' in:
" pos = mean(pos)
)"
Error: unexpected '}' in "}"
I'm not exactly sure what's causing it. I'm on a Windows 11 system, using VSCode as the editor and Radian to run the code. For VSCode extensions I am using: R (REditorSuppor), Markdown All in One (Yu Zhang).
When I run the code on RStudio I do not get an error and the code runs as expected. I'd rather use VSCode and figure out the issue. When searching for an answer online, I've seen issues with unicode characters and actual extra punctuations causing errors. However, as far as I'm aware those don't seem to be the issue here, and how to fix it. Any help would be greatly appreciated. Thank you.
Edit: There is one more detail I forgot to mention above, the summarized function works if it is written as one line:
ratings <- df %>%
dplyr::group_by(rating) %>%
dplyr::summarise(compound = mean(compound), neg = mean(neg), neu = mean(neu), pos = mean(pos))
If you are using radian as your R terminal in VS Code you need to add the following to your user settings.json:
"r.bracketedPaste": true
There are some other useful options in this medium post.
Instructions about how to access your settings.json are set out in the VS Code docs, as well as further information about user and workspace settings.
i am trying to truncate timestamps to milliseconds when writing a parquet file.
with:
tutu <- as.POSIXct("2020/06/03 18:00:00",tz = "UTC")
if i do:
write_parquet(data.frame(tutu),"~/Downloads/tutu.test.parquet")
i get 1591207200000000
if i do:
write_parquet(data.frame(tutu),"~/Downloads/tutu.test.parquet", coerce_timestamps = "ms", allow_truncated_timestamps = TRUE)
i get the error message:
Error in parquet___ArrowWriterProperties___Builder__coerce_timestamps(unit) :
argument "unit" is missing, with no default
what am i doing wrong?
thanks in advance.
It's a bug; see discussion on https://issues.apache.org/jira/browse/ARROW-9219
I have written a function in R which extracts data from a database and builds a new table.
My new table is labeled with the date of the extract (build_date_0).
When I'm debugging my function I get the following warning when I look at my date string:
Browse[2]> build_date_0
[1] "2019-05-01"
Warning message:
In get(object, envir = currentEnv, inherits = TRUE) :
restarting interrupted promise evaluation
Questions:
What does this warning mean / what is happening (step-by-step/basics)?
Should I care?
In general how can I find out more about this error?
This is my code:
build_account_db = function(conn = connection_object
,various_inputs = 24){
browser()
# create connection objects
tabs_1 = dplyr::tbl(conn,in_schema("DB_1","VIEW_W") # some table
# create date string
build_date_0 = lubridate::today() %>% as.character()
build_date = str_replace_all(build_date_0,"-+","_")
db_name_1 = paste0('DATABASE.tab_1_',build_date)
db_name_2 = paste0('DATABASE.tab_2_',build_date)
# build query
query_text_1 = tabs_1 %>% select(COL_1) # some query
query_text_1 = tabs_1 %>% select(COL_2)
# build new tables
create_db = DBI::dbSendQuery(conn_t,paste('CREATE TABLE',db_name_1,'AS (',query_text_1,') WITH DATA PRIMARY INDEX (ID_1)'))
create_db2 = DBI::dbSendQuery(conn_t,paste('CREATE TABLE',db_name_2,'AS (',query_text_2,') WITH DATA PRIMARY INDEX (ID_1)'))
}
When I check a variable, I may or may not get this warning (it varies, even if I restart R, and run my code again with a cleared environment)
Browse[2]> build_date
[1] "2019-02-28 11:00:00 AEDT"
Warning message:
In get(object, envir = currentEnv, inherits = TRUE) :
restarting interrupted promise evaluation
What I've tried: I read this question, but it's more about suppressing the error. Also, google.
I found this link on promises and evaluation in R helpful for a related problem: https://mailund.dk/posts/promises-and-lazy-evaluation/. I wonder if after build_date_0 = lubridate::today() %>% as.character() if you add a call to just build_date_0 if that would solve the promise? Good luck!
I am trying to download records from twitter using rtweet. One issue with this is the twitter server needs to wait 15minutes every 18000 records. So, after record number 18000, I receive a data frame with all the records and a nice warning telling me to wait for a bit. search_tweets has an function argument to download more than 18000 records called retryonratelimit. However, this isnt working so I am exploring other options.
I have produced a function, incorporating tryCatch to address this. However, when the warning at 18000 records pops up, tryCatch is saving the warning rather than the data frame which should be spit out before the warning. Something it would not do if 17999 records were downloaded
library(rtweet)
library(RDCOMClient)
library(profvis)
TwitScrape = function(SearchTerm){
ReturnDF = tryCatch({
TempList=NULL
Temp = search_tweets(SearchTerm,n=18000)
TempList = list(as.data.frame(Temp), SearchTerm)
return(TempList)
},
warning = function(TempList){
Comb=NULL
MAXID = min(TempList[[1]]$status_id)
message("Delay for 15 minutes to accommodate server download limits")
pause(901)
TempWarn = search_tweets(TempList[[2]],n=18000, max_id=MAXID)
TempWarn = as.data.frame(TempWarn)
Comb = rbind(TempList[[1]], TempWarn)
CombList = list(Comb, TempList[[2]])
return(CombList)
}
)
}
Searches = c("#MUFC","#LFC", "#MCFC")
TestExpandList=NULL
TestExpand=NULL
TestExpand2=NULL
for (i in seq_along(Searches)){
TestExpandList = TwitScrape(SearchTerm = Searches[i])
TestExpand = TestExpandList[[1]]
TestExpand$Cat = Searches[i]
TestExpand$DownloadDate = Sys.Date()
TestExpand2 = rbind(TestExpand2, TestExpand)
}
I hope this makes sense. If I can offer any more information please let me know. In summary, why is tryCatch saving my warning rather than the data frame I want?
I am not 100% sure what you would like to achieve, but it seems you are using tryCatch with a wrong understanding.
The argument in the warning-handler warning = function(TempList) is the warning itself, i.e. you have named it TempList, but that doesn't mean it will become your TempList variable, it will still just pass the warning into the handler.
Your function TwitScrape is returning ReturnDF by convention, as you are not properly returning anything, I guess that is still what you want and ok.
I would try to re-structure your solution without tryCatch
Thanks for your comments. RolandASc, you were right. I went back to the drawing board. See the working TwitScrape function below:
TwitScrape = function(SearchTerm){
DF=NULL
DF = search_tweets(SearchTerm,n=18001)
Warn = warnings()
if (names(Warn[1]) == "Rate limit exceeded - 88"){
message("paused")
pause(910)
DF2 = search_tweets(SearchTerm,n=18000, max_id = min(DF$status_id))
DF3 = rbind(DF, DF2)
return(DF3)
}
else {
return(DF)
}}
I'm attempting to exclude some words when running hunspell_check on a text block in Rstudio.
ignore_me <- c("Daniel")
hunspell_check(unlist(some_text), ignore = ignore_me, dict = dictionary("en_GB"))
However, whenever I run I get the following error:
Error in hunspell_check(unlist(some_text, dict = dictionary("en_GB"), :
unused argument (ignore = ignore_me))
I've had a look around SO and trawled the documenation but am struggling to figure what's gone wrong.
It looks like you’ve missed a closing bracket after some_text, so it’s passinng ignore as an argument to unlist() rather than hunspell_check().
UPDATE: Ok, I think you were looking at an old version of the documentation. At least that's what I did at first (https://www.rdocumentation.org/packages/hunspell/versions/1.1/topics/hunspell_check). In the current version, 2.9, ignore is no longer an argument for hunspell_check(). Instead, use add_words in the call to dictionary():
library(hunspell)
some_text <- list("hello", "there", "Daniell")
hunspell_check(unlist(some_text), dict = dictionary("en_GB"))
# [1] TRUE TRUE FALSE
ignore_me <- "Daniell"
hunspell_check(unlist(some_text), dict = dictionary("en_GB", add_words = ignore_me))
# [1] TRUE TRUE TRUE