8

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?

alvas
  • 115,346
  • 109
  • 446
  • 738
Quazi Marufur Rahman
  • 2,603
  • 5
  • 33
  • 51
  • 2
    Have you tried it with `read.csv`. I tried with `read_csv` and couldn't get any error. I used readr_0.2.2 – akrun Oct 29 '15 at 12:37
  • I’m assuming you’re referring to `readr::read_csv`? **Say so**. – Konrad Rudolph Oct 29 '15 at 12:39
  • 2
    I think your session is messed up. `OlsonNames` doesn't seem related, and even if it is, you should have this function. Try restarting your R session. – David Arenburg Oct 29 '15 at 12:41
  • what is the result of `find("read_csv")` ? – Ben Bolker Oct 29 '15 at 12:42
  • Thanks. read.csv() has solved the error. @BenBolker > find("read_csv") [1] "package:readr". But why negative vote? – Quazi Marufur Rahman Oct 29 '15 at 12:42
  • 2
    @DavidArenburg No, it’s related: `readr::read_csv` calls `locale` which in turn calls `check_tz`, which uses `OlsonNames`. And yes, the R session seems to be messed up. – Konrad Rudolph Oct 29 '15 at 12:45
  • I have exactly the same problem and I think it's a version error. Instead of asking another question and get closed, might as well just add to the question and wait for the OP to confirm it =) @qmaruf, please confirm this. – alvas Nov 29 '15 at 17:44
  • @alvas imho, your session info under OP's question doesn't really aid in answering their question. – Heroka Nov 29 '15 at 17:48
  • @heroka, no problem, I have added the info into my answer instead – alvas Nov 29 '15 at 17:50

2 Answers2

3

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  
alvas
  • 115,346
  • 109
  • 446
  • 738
  • Although this answer works, it would be nice if someone gives an authoritative answer as to why the error occurs and why updating R works. – alvas Nov 29 '15 at 17:48
  • Using read.csv() has solved the issue. As I am beginner, I don't know the exact reason. – Quazi Marufur Rahman Dec 02 '15 at 10:33
  • I'm not sure too, I think it's an old version of `readr.read.csv()` vs the newer version of `readr.read_csv()`. I'm not very sure how R's `readr` package works. Someone more experienced should answer that =( – alvas Dec 02 '15 at 10:41
3

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/

biocyberman
  • 5,675
  • 8
  • 38
  • 50
  • I agree that updating R often solves the problem on linux but there's nothing wrong with my session when that `OlsonNames` error occurs because that's the first R session created since I did `sudo apt-get install r-base r-base-dev` and then in R `install.package('readr')`on that particular machine. So it couldn't have been an error of the session. – alvas Dec 04 '15 at 10:01