[R-sig-Geo] reading a gps from R

Roger Bivand Roger.Bivand at nhh.no
Sun Jan 14 21:42:28 CET 2007


On Sun, 14 Jan 2007, Patrick Giraudoux wrote:

> Roger Bivand a écrit :
> > Patrick,
> >
> > On Sun, 14 Jan 2007, Patrick Giraudoux wrote:
> >
> >   
> >> Sorry to answer to myself. I have found a solution for the 2nd question: 
> >> from R within windows the gps can be read with:
> >>
> >> shell("gpsbabel -w -i garmin -f com4: -o openoffice -F \"wpt.txt\"")
> >>
> >>     
> >
> > Good.
> >
> >   
> >> The 1th question about reading the gps data directly to an R object 
> >> unstead of a text file is still unanswered...
> >>
> >>     
> >
> > Since the files are not too large, would pasting an R temporary file into 
> > the system call, and then reading from it be a fix?
> Yes!!! Excellent idea...
> >  I've tried "-" as the 
> > file name under Linux, and it does return the data to stdout (terminal 
> > screen), but I haven't got any further because on RedHat EL 4 I can't see 
> > how to use gpsbabel without being administrator (I've tried both the FC 
> > tips on the gpsbabel website with no effect). system(intern=TRUE) should 
> > grab that output:
> >
> > wps <- system("gpsbabel -w -i garmin -f usb: -o tabsep -F -", intern=TRUE)
> > wps_df <- read.table(textConnection(wps), fill=TRUE)

If gpsbabel is on your Windows path, this should work on XP too, certainly 
the command itself works in a console (for me, with a Garmin USB cable).

> >
> > but there is a lot of unneeded information there. Could the xcsv format be 
> > used with a suitable style?
> >   
> I will explore that next week-end. Not to be an administrator seems not 
> to be a problem here with Ubuntu.
> 
> Anyway using a temporary file may make it for sure if one cannot go 
> through with writing straight into R
> 

Using intern=TRUE passes the whole text output to an R character vector, 
one element per waypoint. Then textConnection() reads the character vector 
as if it was a file - that should avoid the temporary file. It would be 
nice to choose the specific columns needed.

Roger

> Thanks a lot for the hint anyway..
> 
> Best wishes,
> 
> Patrick
> 
> > Best wishes,
> >
> > Roger
> >
> >
> >   
> >> Cheers,
> >>
> >> Patrick
> >>
> >>
> >>
> >> Patrick Giraudoux a écrit :
> >>     
> >>> Dear Listers,
> >>>
> >>> I am trying to write R fonctions to read data from a gps through 
> >>> gpsbabel.
> >>>
> >>> Within linux I have tried this (read garmin gps and write a tab 
> >>> delimited text file wp.txt) and it works well:
> >>>
> >>> system("gpsbabel -w -i garmin -o openoffice /dev/ttyUSB0 
> >>> /home/giraudoux/wp.txt")
> >>>
> >>> I have two questions:
> >>>
> >>> 1/ I wonder whether it would be technically possible to open the 
> >>> connexion directly to a R object (eg data.frame) rather than to write 
> >>> a text file (here wp.txt) ?
> >>>
> >>> 2/ I wonder how to open a USB device/port within a windows XP 
> >>> environment (linux equivalent of /dev/ttyUSB0).
> >>>
> >>> Thanks in advance for any hint...
> >>>
> >>> Patrick
> >>>
> >>>
> >>>
> >>>       
> >> _______________________________________________
> >> R-sig-Geo mailing list
> >> R-sig-Geo at stat.math.ethz.ch
> >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >>
> >>     
> >
> >   
> 
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no




More information about the R-sig-Geo mailing list