r - RStudio:仅显示以前代码的结果
问题描述
我正在使用 Rstudio 上的 rtweet 包在 Twitter 上进行情绪分析。
起初,我想使用 rtweet 包中的这个函数从 Twitter 获取 1000 条推文,效果很好:
Onlinesc <- search_tweets("online schooling", n=1000, include_rts = FALSE, retryonratelimit = TRUE)
Onlinesc$text
之后,无论我更改要查看的推文数量多少次,它仍然会显示与之前显示的相同的 1000 条推文。我认为它保存在程序中的某个位置,并阻止控制台显示新结果。
我试过的:
- 每次运行代码之前清除 Rstudio 的环境和历史记录
- 创建一个新的 R 脚本
- 重启 Rstudio 和我的电脑
- 重新加载包
- 我使用了 twitteR 包中的一个函数来提取推文,但最终遇到了同样的问题
- 重新生成了我的 Twitter 开发者令牌并多次更新了我的 Twitter Oauth
我正在使用 Rstudio 版本 1.3.1093
任何帮助将不胜感激:)
解决方案
我假设这与 retryonratelimit 参数有关。
我运行你的代码来检索 1000 条推文,发现它产生的 df 有 1408 条推文。保持代码相同,但将 n 更改为 500,它生成了相同的数据帧,包含 1408 条推文,而不是 500 条。
我不知道在 retryonratelimit 设置为 false 的代码的第一次调用中获得 999 条推文而不是 1000 条是怎么回事,但是我指定 n=500 的调用让我得到 500 条推文就好了。
这是我的代码。
library(rtweet)
# Original code produces 1408 tweets, not 1000.
Onlinesc <- search_tweets("online schooling", n=1000, include_rts = FALSE, retryonratelimit = TRUE)
Onlinesc$text[1]
length(Onlinesc$text)
# What if we reduce the n to 500 instead of 1000? Nope, still 1408.
Onlinesc500 <- search_tweets("online schooling", n=500, include_rts = FALSE, retryonratelimit = TRUE)
Onlinesc500$text[1]
length(Onlinesc500$text)
# Are these two sets identical? Yep.
sum(Onlinesc$text == Onlinesc500$text) == length(Onlinesc$text)
# We can see the last 6 tweets are identical.
tail(Onlinesc$text)
tail(Onlinesc500$text)
# So what gives?
# Looks like both the 1000 and 500 tweet dfs have 1408 observations. Why not the appropriate n we specify?
# Could this be due to the retryonratelimit argument? Let's see by adjusting it to false.
F_Onlinesc <- search_tweets("online schooling", n=1000, include_rts = FALSE, retryonratelimit = FALSE)
length(F_Onlinesc$text) # Interesting. We've got 999 tweets instead of 1000.
F_Onlinesc500 <- search_tweets("online schooling", n=500, include_rts = FALSE, retryonratelimit = FALSE)
length(F_Onlinesc500$text) # 500. We've got the appropriate number of tweets from this call.
F_Onlinesc$text[1] == F_Onlinesc500$text[1] # The first tweet is identical, which is to be expected. We get the most recent ones first.
tail(F_Onlinesc$text) == tail(F_Onlinesc500$text) # The last six tweets are dissimilar, which is to be expected.
推荐阅读
- spring-boot - 使会话无效并从资源服务器访问数据后的 Spring Boot OAuth2 错误
- android - 如何将 ViewPager 的第一个 Fragment 替换为另一个 Fragment 并与前一个 Fragment 处于相同位置
- arrays - 如何计算这些大于数组中第 12 个元素的数字?
- python - 使用 YOLOv3/Tensorflow 检测时出现 KeyError
- laravel - 在laravel中调度每个作业后如何登录数据库?
- julia - 从 Plots.jl 中的终端运行时显示的绘图窗口
- r - 从 csv 文件可视化 R 中的箱线图
- python-3.x - 通过将字符串从 Python 中的文本文件转换为十六进制来生成十六进制文件
- groovy - 以其他用户身份登录时脚本运行程序/复制项目
- python - 为 DataFrameGroupBy 对象生成的图中的每一行生成标签