简体   繁体   中英

coercing argument is not an atomic vector (repeating endlessly)

Newbie question here. I'm trying to run some code that will extract the usernames and dates from a list of assembled web pages. This was working perfectly fine before, but now when I run the code I keep getting the error "coercingargument is not an atomic vector" which repeats endlessly.

I've tried reviewing previous answers here but nothing seemed to quite work. I can't understand why it suddenly stopped working even though nothing has changed. My feeling is I either removed a library it needed or something hasn't quite reset. Any help would be warmly appreciated.

# COLLECT THE DATES
for (i in urls3) {
  addurl <- i
  discussion <- read_html(i, timeout = 1000000000)
  usernames <- discussion %>% 
  html_nodes(".lia-component-message-view-widget-author-username a") %>% 
  html_text()
  all.usernames <- append(all.usernames, usernames)
  datetime <- discussion %>% 
  html_nodes(".local-friendly-date")
  datetime <- str_extract(datetime, "[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2} [A-Z]{2}")
  datetime <- parse_date_time(datetime, "%Y-%m-%d %H:%M:%p", tz = "US/Eastern")
  datetime <- as.character(datetime)
  date.posted <- datetime[1]
  date.replied <- datetime[2]
  date.difference <- difftime(datetime[2],datetime[1], units=c("mins"))

  new.table <- rbind(new.table,c(addurl, date.posted, date.replied, date.difference))
}

The expected results would be a table with the URL, date posted, date replied, and date difference.

The actual results are "argument is not an atomic vector; coercingargument is not an atomic vector; coercingargument is not an atomic vector; coercingargument is not an atomic vector; ..."

You need these packages to make your code work :

library(textreadr)
library(dplyr)
library(rvest)
library(stringr)
library(lubridate)

You could ckeck where in the for loop it is bugging and last be careful when you concatenate to have the same object in the two sides.

append, c, rbind

You have two package with read_html function be careful. You will gained clearness to give a more syntetic example. I hope it will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM