how to import .rec files in R

912 Views Asked by At

I have a .rec file that I want to import into R. I have saved the .rec file to my working directory. This is what I have tried.

library(foreign)  
library(RODBC)  
data.test <- read.epiinfo("data_in.rec")  

I get this error:

Error in if (headerlength <= 0L) 
stop("file has zero or fewer variables: probably not an EpiInfo file") : 
  missing value where TRUE/FALSE needed

In addition: Warning messages:

1:

In readLines(file, 1L, ok = TRUE) :
  line 1 appears to contain an embedded nul

2:

In strsplit(line, " ") : input string 1 is invalid in this locale

I have looked online and in the read.epiinfo help package in R. The help package says

Some later versions of Epi Info use the Microsoft Access file format to store data. That may be readable with the RODBC package.

I have two questions.
1. Is the error I am getting because the .rec file I have is from an Epi Info version later than 6?
2. How do I use the RODBC library to open the .rec file?

1

There are 1 best solutions below

0
On

The .rec (or .REC) file turned out to be a .EDF (European Data Format) file type. It was easily opened in R using the library edfReader. The edfReader library help file is very useful for opening the file and extracting the time series data. See code below for what I used. Code was adapted from the help file.

install.packages('edfReader')
library(edfReader)
?edfReader  
lib.dir <- system.file("data_in.rec",package="edfReader")  
Cfile <- paste(lib.dir,'/edfPlusC.edf',sep='')  
CHdr <- readEdfHeader("data_in.rec")  
CSignals <- readEdfSignals(CHdr)  
summary(CSignals)