如何解决任务计划程序中带有西里尔符号的 R 脚本编码问题
我有一个 R 脚本,其中包含西里尔符号(作为过滤术语)。它以 UTF-8 编码保存,语言环境选项设置为 Sys.setlocale('LC_ALL',"Ukrainian")
。当我手动运行它时,它工作得很好。我想通过 Windows 任务调度程序运行这个脚本。通常,它可以工作(并生成带有未失真符号的结果数据集),但它不会按用西里尔文书写的术语进行过滤。
我想知道如何解决这个问题?
脚本,实际上看起来像
library(tidyRSS)
library(googlesheets4)
library(dplyr)
library(plyr)
library(adapr)
library(devtools)
library(xlsx)
#devtools::install_github("cran/adapr")
Sys.setlocale('LC_ALL',"Ukrainian")
my_feed1 <- tidyfeed("https://www.vugledar-rada.gov.ua/index.php?format=feed&type=rss")
my_feed2 <- tidyfeed("https://ugledar.info/feed")
to_filter <- rbind.fill(my_feed1,my_feed2)
term <- which(grepl("город",to_filter$item_title) | grepl("город",to_filter$item_description) | grepl("місто",to_filter$item_title) | grepl("місто",to_filter$item_description))
filtered <- to_filter[c(term),]
d <- Sys.Date()
t <- Sys.time()
print("saving to the disk...")
setwd("C:\\Users\\user\\Desktop\\Hanna K\\Newsfeed")
write.xlsx(filtered,paste0("check_news__",d,".xlsx"))
解决方法
很难猜测问题的确切来源,但我强烈怀疑它与编码有关。
尝试通过打印检查控制台和任务调度程序中的编码
options("encoding")
如果编码不同,那么您可以在脚本顶部设置编码:
options(encoding = "myencoding")
确认第一个命令确实改变了编码。
祝你好运!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。