【问题标题】:R script with cyrillic symbols in Task Scheduler. Encoding issue任务计划程序中带有西里尔符号的 R 脚本。编码问题
【发布时间】:2021-05-18 07:47:49
【问题描述】:

我有一个 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"))

【问题讨论】:

  • 您能发布任务调度程序启动的 R 脚本吗?我想知道这是否与您加载 R 脚本的方式有关。也许是带有编码的来源。例如。 source("myscript.R", encoding = "UTF-8") (或您的脚本使用的任何编码)
  • @Jagge 我已将其添加到问题中

标签: r windows taskscheduler windows-task-scheduler


【解决方案1】:

很难猜出问题的确切来源,但我强烈怀疑它与编码有关。

尝试通过打印检查控制台和任务调度程序中的编码

options("encoding")

如果编码不同,那么您可以在脚本顶部设置编码:

options(encoding = "myencoding")

确认第一个命令确实改变了编码。

祝你好运!

【讨论】:

    猜你喜欢
    • 2022-10-19
    • 1970-01-01
    • 2020-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-31
    • 2015-07-28
    • 2013-09-26
    相关资源
    最近更新 更多