简体   繁体   English

使用带有readr包的read_csv时找不到函数“OlsonNames”

[英]Could not find function “OlsonNames” when using read_csv with readr package

I am trying to read a csv file using read_csv() of R. 我正在尝试使用R的read_csv()读取csv文件。

library(readr)
data <- read_csv("data/tmp.csv")

tmp.csv is given below. tmp.csv如下。

"A", "B", "C", "D", "E", "F", "G", "H", "I"
1,5,2015-07-31,5263,555,1,1,"0","1"
2,5,2015-07-31,6064,625,1,1,"0","1"
3,5,2015-07-31,8314,821,1,1,"0","1"
4,5,2015-07-31,13995,1498,1,1,"0","1"
5,5,2015-07-31,4822,559,1,1,"0","1"
6,5,2015-07-31,5651,589,1,1,"0","1"
7,5,2015-07-31,15344,1414,1,1,"0","1"
8,5,2015-07-31,8492,833,1,1,"0","1"
9,5,2015-07-31,8565,687,1,1,"0","1"

But it produces the following error. 但它会产生以下错误。

Error in match(x, table, nomatch = 0L) : 
  could not find function "OlsonNames"

How can I solve this error? 我该如何解决这个错误? I have googled using the error, but haven't found any relevant solution. 我用google搜索错误,但没有找到任何相关的解决方案。


After some digging, the same error occurs with: 经过一番挖掘后,出现同样的错误:

> locale()
Error in match(x, table, nomatch = 0L) : 
  could not find function "OlsonNames"

It seems like an error relating to https://stat.ethz.ch/R-manual/R-devel/library/base/html/timezones.html 这似乎是与https://stat.ethz.ch/R-manual/R-devel/library/base/html/timezones.html相关的错误

Restarting the R session doesn't work. 重新启动R会话不起作用。

How should I resolve the error? 我该如何解决这个错误? Do I need to install some packages? 我需要安装一些包吗? If so, which? 如果是这样,哪个?

Updating R seems to resolve the problem. 更新R似乎解决了这个问题。

To update to R 3.2.2 for Ubuntu 14.04 ( ONLY WORKS for Ubuntu 14.04 Trusty , update the deb packages properly if you're not using 14.04): 要更新到R 3.2.2 for Ubuntu 14.04仅适用于Ubuntu 14.04 Trusty ,如果您不使用14.04,请正确更新deb软件包):

sudo echo 'deb http://cran.es.r-project.org/bin/linux/ubuntu trusty/' >> /etc/apt/sources.list
gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9
gpg -a --export E084DAB9 | sudo apt-key add -
sudo apt-get update
sudo apt-get upgrade

(Update instructions from: http://ubuntuforums.org/showthread.php?t=2264580 ) Then in the latest version of R: (更新说明来自: http//ubuntuforums.org/showthread.php?t = 2264580 )然后在最新版本的R中:

> install.packages('readr')
> library(readr)
> locale()
<locale>
Numbers:  123,456.78
Formats:  %Y%.%m%.%d / %H:%M
Timezone: UTC
Encoding: UTF-8
<date_names>
Days:   Sunday (Sun), Monday (Mon), Tuesday (Tue), Wednesday (Wed), Thursday
        (Thu), Friday (Fri), Saturday (Sat)
Months: January (Jan), February (Feb), March (Mar), April (Apr), May (May),
        June (Jun), July (Jul), August (Aug), September (Sep), October
        (Oct), November (Nov), December (Dec)
AM/PM:  AM/PM

Now loading the read_csv works without the OlsonNames error. 现在加载read_csv工作没有OlsonNames错误。


Before updating my R, this is my R version: 在更新我的R之前,这是我的R版本:

> version
               _                           
platform       x86_64-pc-linux-gnu         
arch           x86_64                      
os             linux-gnu                   
system         x86_64, linux-gnu           
status                                     
major          3                           
minor          0.2                         
year           2013                        
month          09                          
day            25                          
svn rev        63987                       
language       R                           
version.string R version 3.0.2 (2013-09-25)
nickname       Frisbee Sailing  

Let's say a package Pkg has a function Foo . 假设包Pkg具有Foo功能。

When you see a message like: 当您看到如下消息时:

Could not find function Foo

this means Pkg has not been loaded successfully (ie by library/require command).Or if Pkg is required indrectly by your package (ie readr in this case) it may be that Pkg is not installed, or your R installation is somehow broken. 这意味着Pkg尚未成功加载(即通过library/require命令)。或者如果您的包正确需要Pkg (在本例中为readr ),则可能是Pkg未安装,或者您的R安装以某种方式被破坏。 That's why an update/upgrade or even restart the computer may help. 这就是为什么更新/升级甚至重新启动计算机可能会有所帮助。

In this case the function OlsonNames (try typing this in R console: ??OlsonNames ) is an alias to base::Sys.timezone function. 在这种情况下,函数OlsonNames (尝试在R控制台中输入: ??OlsonNames )是base::Sys.timezone函数的别名。 Because it belongs to the base package, which is certainly has been installed, it is likely that something odd happened with your R installation. 因为它属于基本软件包,当然已经安装了,所以R安装可能会发生奇怪的事情。 Then again, a fresh R session by restarting or update/upgrade of R may help. 然后,重新启动或更新/升级R的新R会话可能会有所帮助。

Bonus: This is often overlooked by many, an easy method given by R developers themselves to get the latest version of R on Linux : 额外奖励:许多人经常忽略这一点,这是R开发人员自己在Linux上获取最新版R的简单方法:

Select a mirror near you from here: https://cran.r-project.org/mirrors.html For example, I select a mirror in Denmark, then read the README. 从这里选择您附近的镜像: https//cran.r-project.org/mirrors.html例如,我在丹麦选择一个镜像,然后阅读README。 http://mirrors.dotsrc.org/cran/bin/linux/ubuntu/README.html http://mirrors.dotsrc.org/cran/bin/linux/ubuntu/README.html

I also had great comfort to maintain R installation on Windows with installr package. 我还非常installr使用installr软件包在Windows上维护R安装。 Github: https://github.com/talgalili/installr/ Github: https//github.com/talgalili/installr/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM