davidcarslaw / openair

Tools for air quality data analysis
https://davidcarslaw.github.io/openair/
GNU General Public License v2.0
307 stars 113 forks source link

Error in import... : could not find function "import" #320

Closed manleiva closed 1 year ago

manleiva commented 1 year ago

I have a problem with import function in ‘openair’ version 2.14 Xcode Version 14.2 R version 4.2.2 RStudio Versión 2022.12.0+353

The code give the problem is

FileAsHIS<-import("dis-As-qco-QNTIII.csv", file.type = "csv", sep = ";", na.strings=c("NA", "NV","NaN"), date = "Date") Error in import("dis-As-qco-QNTIII.csv", file.type = "csv", sep = ";", : could not find function "import"

Some ideas?

Manuel

The data are dateCD;Date;MES;ANNO;As;As_ng 2/1/2010;2/1/2010 23:00;1;2010;;NA 5/1/2010;5/1/2010 23:00;1;2010;;NA 8/1/2010;8/1/2010 23:00;1;2010;;NA 11/1/2010;11/1/2010 23:00;1;2010;;NA 14/1/2010;14/1/2010 23:00;1;2010;;NA 17/1/2010;17/1/2010 23:00;1;2010;;NA 20/1/2010;20/1/2010 23:00;1;2010;;NA 23/1/2010;23/1/2010 23:00;1;2010;;NA 26/1/2010;26/1/2010 23:00;1;2010;;NA 29/1/2010;29/1/2010 23:00;1;2010;;NA 1/2/2010;1/2/2010 23:00;2;2010;;NA 4/2/2010;4/2/2010 23:00;2;2010;;NA 7/2/2010;7/2/2010 23:00;2;2010;;NA 10/2/2010;10/2/2010 23:00;2;2010;;NA 13/2/2010;13/2/2010 23:00;2;2010;;NA 16/2/2010;16/2/2010 23:00;2;2010;;NA 19/2/2010;19/2/2010 23:00;2;2010;;NA 22/2/2010;22/2/2010 23:00;2;2010;;NA 25/2/2010;25/2/2010 23:00;2;2010;;NA 28/2/2010;28/2/2010 23:00;2;2010;;NA 3/3/2010;3/3/2010 23:00;3;2010;;NA

jack-davison commented 1 year ago

Hi Manuel,

import() was removed from openair in the most recent update; there are now so many tools provided in base R and extension packages (e.g., readr for reading data and lubridate for handling dates) that there wasn't cause to maintain import() any further.

However, you should be able to read in your data using purely Base R by using code along these lines:

# read data
data <-
  read.delim(file = "dis-As-qco-QNTIII.csv",
             sep = ";",
             na.strings = c("NA", "NV", "NaN"))

# format "Date" as date
data$Date <- as.POSIXct(data$Date, format = "%d/%m/%Y %H:%M") 
      dateCD                Date MES ANNO As As_ng
1   2/1/2010 2010-01-02 23:00:00   1 2010 NA    NA
2   5/1/2010 2010-01-05 23:00:00   1 2010 NA    NA
3   8/1/2010 2010-01-08 23:00:00   1 2010 NA    NA
4  11/1/2010 2010-01-11 23:00:00   1 2010 NA    NA
5  14/1/2010 2010-01-14 23:00:00   1 2010 NA    NA
6  17/1/2010 2010-01-17 23:00:00   1 2010 NA    NA
7  20/1/2010 2010-01-20 23:00:00   1 2010 NA    NA
8  23/1/2010 2010-01-23 23:00:00   1 2010 NA    NA
9  26/1/2010 2010-01-26 23:00:00   1 2010 NA    NA
10 29/1/2010 2010-01-29 23:00:00   1 2010 NA    NA
11  1/2/2010 2010-02-01 23:00:00   2 2010 NA    NA
12  4/2/2010 2010-02-04 23:00:00   2 2010 NA    NA
13  7/2/2010 2010-02-07 23:00:00   2 2010 NA    NA
14 10/2/2010 2010-02-10 23:00:00   2 2010 NA    NA
15 13/2/2010 2010-02-13 23:00:00   2 2010 NA    NA
16 16/2/2010 2010-02-16 23:00:00   2 2010 NA    NA
17 19/2/2010 2010-02-19 23:00:00   2 2010 NA    NA
18 22/2/2010 2010-02-22 23:00:00   2 2010 NA    NA
19 25/2/2010 2010-02-25 23:00:00   2 2010 NA    NA
20 28/2/2010 2010-02-28 23:00:00   2 2010 NA    NA
21  3/3/2010 2010-03-03 23:00:00   3 2010 NA    NA