在粘贴功能中使用日语字母 [英] Using Japanese letters in paste function
问题描述
我想从Google趋势中下载日语和英语搜索字词的搜索查询数据.当我仅使用英文搜索字词时,它就可以很好地工作,但是一旦包含日语字母,它就无法工作.
I want to download search query data from google trends for both japanese and english search terms. It works perfectly fine when I use english search terms only, but it does not work as soon as I include japanese letters.
我的代码如下(我为该示例添加了默认关键字,以使其更易于使用):
My code is the following(I included the default keyword just for this example to make it easier to use):
URL_GT=function(keyword="Toyota Aygo %2B Toyota Yaris %2B Toyota Vitz %2B
トヨタヴィッツ", year=2010, month=1, length=68){
start="http://www.google.com/trends/trendsReport?hl=en-US&q="
end="&cmpt=q&content=1&export=1"
date=""
queries=keyword[1]
if(length(keyword)>1) {
for(i in 2:length(keyword)){
queries=paste(queries, "%2C ", keyword[i], sep="")
}
}
#Dates
if(!is.na(year)){
date="&date="
date=paste(date, month, "%2F", year, " ", month+length-1, "m", sep="")
}
URL=paste(start, queries, date, end, sep="")
browseURL(URL)
}
当我查看浏览器中调用的下载URL时,可以看到日语字母已转换为%,数字和字母,但它们根本不会改变.
When I look at the download URL that gets called in my browser I can see that the japanese letters got transformed into some %, numbers and letters, but they are not supposed to change at all.
当我使用
Sys.setlocale("LC_CTYPE","japanese_JAPAN")
我得到以下粘贴结果
paste("トヨタヴィッツ","Toyota Vitz", sep = "")
[1] "ƒgƒˆƒ^ƒ"ƒBƒbƒcToyota Vitz"
我认为这很好地表明了paste()函数似乎无法按预期工作.
I think this shows pretty good that the paste() function seems not to work as intended.
使用
Sys.setlocale("LC_CTYPE","german_GERMANY")
我收到以下错误消息
unexpected INCOMPLETE_STRING
1: URL_GT=function(keyword="Toyota Aygo %2B Toyota Yaris %2B Toyota Vitz %2B ?
表明R无法解释日语字母.
indicating that R cannot interpret the japanese letters.
我试图找到一种解决方案,但只能找到一些提示,这些提示导致我更改了语言环境.如上所述,到目前为止,这对我没有用.我还发现了这个提示,但是我遇到了同样的错误作为该问题的询问者-即
I tried finding a solution, but could only find tips which led me to change my locale. As discribed above this did not work for me so far. I also found this tip, but I got the same error as the enquirer of that question - namely
Warning message: In Sys.setlocale("LC_CTYPE", "UTF-8") : OS reports request
to set locale to "UTF-8" cannot be honored
非常感谢您的帮助!既然这是我的第一篇文章,我希望关于结构和细节的一切都很好.
I am very grateful for any help! Since this is my first post ever I hope that everything concerning structure and detail is alright.
推荐答案
我找到了一个对我来说很好的解决方案.为了使日语本地用户正常工作,我不得不更改与unicode不兼容的程序的语言.
I found a solution that works just fine for me. I had to change the language for unicode-incompatible programs in order for the japanese local to work properly.
在Windows 8.1上,您必须转到控制面板,时间,区域和语言,地区,行政管理,然后您可以在其中相应地更改语言-在我的情况下为日语-之后重新启动计算机.
On Windows 8.1 you have to go to the control panel, time, region & language, region, administration and there you can change the language accordingly - in my case japanese - restart your pc afterwards.
如果您现在将本地设置为
If you now set your local to
Sys.setlocale("LC_CTYPE","japanese_JAPAN")
键入粘贴内容应返回您要求的内容,例如
typing in paste should return what you asked for e.g.
paste("It works", "トヨタヴィッツ", sep=" ")
[1] "It works トヨタヴィッツ"
唯一让我感到困惑的是,下载后我打开Excel文件时,日语字母以一种新的讽刺的方式出现.
The only thing that still confuses me is that when I open the Excel file after the download the Japanese letters appear in a new criptic way.
我尝试手动下载单词的数据,并在Excel文件中获得相同的结果.所以我想数据应该是正确的.不幸的是,在更改unicode语言以查看excel是否也将它弄乱之前,我没有下载日语数据的CSV文件.但是,当我再次将设置恢复为德语时,下载的文件中也出现了相同的抄写字母.
I tried downloading the data for the word manually and get the same result in the Excel file. So I guess the data should be the correct one. Unfortunately I did not download a CSV file of the japanese data before I changed my unicode language to see if excel messed it up there as well. But when I restored my settings to german again the same criptic letters appeared in the downloaded file.
这篇关于在粘贴功能中使用日语字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!