Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find function "OlsonNames" when using read_csv with readr package

Tags:

r

csv

readr

I am trying to read a csv file using read_csv() of R.

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

tmp.csv is given below.

"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.


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

Restarting the R session doesn't work.

How should I resolve the error? Do I need to install some packages? If so, which?

like image 247
Quazi Marufur Rahman Avatar asked Oct 29 '15 12:10

Quazi Marufur Rahman


Video Answer


2 Answers

Updating R seems to resolve the problem.

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):

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:

> 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.


Before updating my R, this is my R version:

> 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  
like image 69
alvas Avatar answered Sep 30 '22 12:09

alvas


Let's say a package Pkg has a function Foo.

When you see a message like:

Could not find function Foo

this means Pkg has not been loaded successfully (i.e. by library/require command).Or if Pkg is required indrectly by your package (i.e. readr in this case) it may be that Pkg is not installed, or your R installation is somehow broken. 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. Because it belongs to the base package, which is certainly has been installed, it is likely that something odd happened with your R installation. Then again, a fresh R session by restarting or update/upgrade of R may help.

Bonus: This is often overlooked by many, an easy method given by R developers themselves to get the latest version of R on Linux:

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. http://mirrors.dotsrc.org/cran/bin/linux/ubuntu/README.html

I also had great comfort to maintain R installation on Windows with installr package. Github: https://github.com/talgalili/installr/

like image 29
biocyberman Avatar answered Sep 30 '22 12:09

biocyberman