Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从r中的Search()创建的数据帧,但在使用结果数据帧时,接收错误“conn”必须是弹性连接对象_R_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Rstudio - Fatal编程技术网 elasticsearch,rstudio,R,elasticsearch,Rstudio" /> elasticsearch,rstudio,R,elasticsearch,Rstudio" />

从r中的Search()创建的数据帧,但在使用结果数据帧时,接收错误“conn”必须是弹性连接对象

从r中的Search()创建的数据帧,但在使用结果数据帧时,接收错误“conn”必须是弹性连接对象,r,elasticsearch,rstudio,R,elasticsearch,Rstudio,我在R中使用弹性包,弹性搜索版本号为6.8.3,弹性包的版本为“1.0.0”。我有一个基于关键字输入列表搜索elastic的函数,输出是hits$hits的数据帧。该数据帧随后用于另一个函数,该函数执行数据操作并绘制绘图 但是,当我在数据操作函数中使用生成的数据帧时,我在运行数据操作函数的某个部分时不断遇到这个错误,其中甚至没有提到弹性:错误:“conn”必须是弹性连接对象;看到了吗?连接 这是弹性函数: keyword_search <- function(file) { libra

我在R中使用弹性包,弹性搜索版本号为6.8.3,弹性包的版本为“1.0.0”。我有一个基于关键字输入列表搜索elastic的函数,输出是hits$hits的数据帧。该数据帧随后用于另一个函数,该函数执行数据操作并绘制绘图

但是,当我在数据操作函数中使用生成的数据帧时,我在运行数据操作函数的某个部分时不断遇到这个错误,其中甚至没有提到弹性:错误:“conn”必须是弹性连接对象;看到了吗?连接

这是弹性函数:

keyword_search <- function(file) {
  library(elastic)
  library(readxl)
  library(rjson)
  library(magrittr)

  con <- connect(host = '10.0.53.250', port = 9200)

#file is an excel file with "keyword" in the first cell of the first column, #then one search term per cell going down the column
  the_terms <- read_excel(file)
  the_terms %>%
    na.omit() %>%
    as.list()
  r <- data.frame()

  for (t in the_terms$keyword) {
    print(t)
    result <- Search(con, index="cars", body = paste0('{"query": {"match_phrase" : {"body_":', '"', t, '"', '}}}'), asdf = TRUE, size = 5000)
    r <- rbind(r, result$hits$hits)
  }
icars <- r
return(icars)
}
wordcloud_table  <- function(icars) {

  library(wordcloud2)
  library(dplyr)
  library(readxl)
  library(tidytext)
  library(wordcloud)
  library(tidyr)
  data(stop_words)
  source('stemmer.R')

  custom_stopwords <- c('1', '2', '3', '4', '5', '6', '7', '8', '9', '0',  'hey', 'hehe')

  custom_stopwords_df <- tibble(word = custom_stopwords)

  clean_cars_df <- icars %>% 
    dplyr::select(report_name, body_)

  tidy_cars<- clean_cars_df %>%
    unnest_tokens(word, body_)

  stopwords_df<- tibble(word = stopwords())

  tidy_cars <- tidy_cars %>%
    anti_join(stopwords_df)

  tidy_cars <- tidy_cars %>%
    anti_join(stop_words)

  tidy_cars <- tidy_cars %>%
    anti_join(custom_stopwords_df)

  wordcountdata <- tidy_cars %>% count(word)

  forwordcloud <- as.data.frame(wordcountdata)
  return(forwordcloud)
}

您有冲突的函数名:elastic::count和dplyr::count。如果两个包都已加载,则一个包将覆盖另一个同名的fxn。您可以通过命名函数all来最轻松地修复此问题,因此只需将count更改为dplyr::count我想您是在尝试使用dplyr的count

就是这样……非常感谢。现在效果很好!我真傻,没意识到这一点
icars <- keyword_search("keywords_onecol.xlsx")

wordcloud_table(icars)
12.
stop("'conn' must be an elastic connection object; see ?connect", 
    call. = FALSE) 
11.
is_conn(conn) 
10.
count(., word) 
9.
function_list[[k]](value) 
8.
withVisible(function_list[[k]](value)) 
7.
freduce(value, `_function_list`) 
6.
`_fseq`(`_lhs`) 
5.
eval(quote(`_fseq`(`_lhs`)), env, env) 
4.
eval(quote(`_fseq`(`_lhs`)), env, env) 
3.
withVisible(eval(quote(`_fseq`(`_lhs`)), env, env)) 
2.
tidy_cars %>% count(word) 
1.
wordcloud_table(icars)