I encounter the following error when I run this code:
Error in check_input(x) :
Input must be a character vector of any length or a list of character
vectors, each of which has a length of 1.
stock_tokens
Error: object 'stock_tokens' not found
The line of code with the unnest_tokens() function seems to be where the error is generated. What might be causing this error?
library(tidyr)
library(dplyr)
>
> Attaching package: 'dplyr'
> The following objects are masked from 'package:stats':
>
> filter, lag
> The following objects are masked from 'package:base':
stock_tokens <- stock_articles %>%
unnest(map(corpus, tidy)) %>%
unnest_tokens(word, text) %>%#encounter input error on this line of code
select(company, datetimestamp, word, id, heading)
> Error in check_input(x): Input must be a character vector of any length or a list of character
> vectors, each of which has a length of 1.
stock_tokens
> Error in eval(expr, envir, enclos): object 'stock_tokens' not found
I encounter the following error when I run this code: Error in check_input(x) : Input must be a character vector of any length or a list of character vectors, each of which has a length of 1.
The line of code with the unnest_tokens() function seems to be where the error is generated. What might be causing this error?
library(tidyr) library(dplyr)
>
> Attaching package: 'dplyr'
> The following objects are masked from 'package:stats':
>
> filter, lag
> The following objects are masked from 'package:base':
>
> intersect, setdiff, setequal, union
library(tidytext) library(tidyverse)
> -- Attaching packages -------------------------------- tidyverse 1.2.1 --
> v ggplot2 2.2.1 v purrr 0.2.5
> v tibble 1.4.2 v stringr 1.3.1
> v readr 1.1.1 v forcats 0.3.0
> -- Conflicts ----------------------------------- tidyverse_conflicts() --
> x dplyr::filter() masks stats::filter()
> x dplyr::lag() masks stats::lag()
library(tm.plugin.webmining)
>
> Attaching package: 'tm.plugin.webmining'
> The following object is masked from 'package:tidyr':
>
> extract
> The following object is masked from 'package:base':
>
> parse
library(purrr)
company <- c("Microsoft", "Apple", "Google", "Amazon", "Facebook") symbol <- c("MSFT", "AAPL", "GOOG", "AMZN", "FB")
download_articles <- function(symbol) { WebCorpus(YahooFinanceSource(paste0("NASDAQ:", symbol)))
}
stock_articles <- data_frame(company = company, symbol = symbol) %>% mutate(corpus = map(symbol, download_articles))
stock_articles
> # A tibble: 5 x 3
> company symbol corpus
>
> 1 Microsoft MSFT
> 2 Apple AAPL
> 3 Google GOOG
> 4 Amazon AMZN
> 5 Facebook FB
stock_tokens <- stock_articles %>% unnest(map(corpus, tidy)) %>% unnest_tokens(word, text) %>%#encounter input error on this line of code select(company, datetimestamp, word, id, heading)
> Error in check_input(x): Input must be a character vector of any length or a list of character
> vectors, each of which has a length of 1.
stock_tokens
> Error in eval(expr, envir, enclos): object 'stock_tokens' not found