You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用tidytext处理邮件文本遇错误:Can't convert a function to a quosure

Fixing the "Can't convert a function to a quosure" Error in tidytext

Hey there! Let's get that word frequency count working for your email text file. The error you're hitting comes from using an outdated function in tidytext—here's how to fix it and get things running smoothly:

Why the Error Happens

You're using unnest_tokens_() (with the underscore), which is the old standard evaluation version of the function. This function has been deprecated in recent tidytext releases, and the modern tidyverse ecosystem now favors non-standard evaluation functions like unnest_tokens() (no underscore). Trying to use the old function with current tidytext versions leads to the quosure conversion error you're seeing.

Corrected Code

Here's the updated script that will work with modern tidytext:

library(tidytext)
library(tibble)

# Read in your email data
data <- read_lines("emails.txt")
text_tibble <- tibble(line = seq_along(data), text = data)

# Tokenize the text (the corrected line!)
text_words <- text_tibble %>% 
  unnest_tokens(word, text)

# Calculate basic word frequencies
word_frequencies <- text_words %>% 
  count(word, sort = TRUE)

Bonus: Clean Up Invalid/Stop Words

Since you mentioned your data has lots of invalid content, you'll probably want to filter out common stop words (like "the", "and") to get meaningful results. Add this step after tokenization:

# Load built-in stop words
data(stop_words)

# Filter out stop words and recalculate frequencies
clean_word_frequencies <- text_words %>% 
  anti_join(stop_words) %>% 
  count(word, sort = TRUE)

Quick Note on Package Version

If you're still having issues, make sure you're running the latest version of tidytext:

update.packages("tidytext")

内容的提问来源于stack exchange,提问作者user9365328

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:10:11