Laurent, Thanks for your suggestions. The following code:
import rpy f = rpy.r.attach('.RDatalongrun',pos=2) dat = rpy.with_mode(rpy.NO_CONVERSION, rpy.r.get)("longrun",pos=2) print "type(dat) = " + str(type(dat)) colnames = rpy.r.colnames(dat) print "type(colnames) = " + str(type(colnames)) print colnames now produces a Python list of the columns: type(dat) = <type 'Robj'> type(colnames) = <type 'list'> ['time', 'index', 'lat', 'lon', 'agl', 'grdht', 'foot', 'sampt', 'temp0', 'swrad', 'zi', 'dens', 'dmass', 'sigmaw', 'TL'] - Tyler Laurent Gautier wrote: > Tyler Erickson wrote: >> I am trying to read in a R-formatted datafile using RPy. When I read in >> the file using R and display the data, the column headers are included. >> >> $ R >>> attach(".RDatalongrun",pos=2) >>> dat<-get("longrun",pos=2) >>> dat[1:5,1:9] >> time index lat lon agl grdht foot >> sampt temp0 >> [1,] -60 1 45.7993 -90.4651 220.1694 496.0374 0.1794837 51.8537 >> 296.35 >> [2,] -60 2 45.7283 -90.7861 1187.4362 366.4808 0.0025203 0.7241 >> 296.77 >> [3,] -60 3 45.7782 -90.5021 237.6977 496.0374 0.1530388 44.1661 >> 296.39 >> [4,] -60 4 45.7706 -90.5811 976.4551 496.0374 0.1043193 30.1000 >> 296.35 >> [5,] -60 5 45.8013 -90.4390 55.8362 496.0374 0.2078631 60.0000 >> 296.30 >> >> >> However, I can't figure out how to determine the column headers when I >> read in the same file with RPy. >> >> $ python >> Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) >> [GCC 4.3.2] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> from rpy import * >>>>> f = r.attach('.RDatalongrun',pos=2) >>>>> dat = r.get("longrun",pos=2) > > You'll most likely have to switch to the NO_CONVERSION mode before > calling r.get(), then you'll be able to call r.colnames() on the > resulting object. > > rpy2 could be making things easier, here with an example from the dev > version: > http://rpy.sourceforge.net/rpy2/doc-dev/html/robjects.html#names > > > > L. > > >>>>> type(dat) >> <type 'numpy.ndarray'> >>>>> dat[0:4,1:8] >> array([[ 1.00000000e+00, 4.57993000e+01, -9.04651000e+01, >> 2.20169400e+02, 4.96037400e+02, 1.79483700e-01, >> 5.18537000e+01], >> [ 2.00000000e+00, 4.57283000e+01, -9.07861000e+01, >> 1.18743620e+03, 3.66480800e+02, 2.52030000e-03, >> 7.24100000e-01], >> [ 3.00000000e+00, 4.57782000e+01, -9.05021000e+01, >> 2.37697700e+02, 4.96037400e+02, 1.53038800e-01, >> 4.41661000e+01], >> [ 4.00000000e+00, 4.57706000e+01, -9.05811000e+01, >> 9.76455100e+02, 4.96037400e+02, 1.04319300e-01, >> 3.01000000e+01]]) >> >> >> ------------------------------------------------------------------------------ >> >> Crystal Reports - New Free Runtime and 30 Day Trial >> Check out the new simplified licensing option that enables unlimited >> royalty-free distribution of the report engine for externally facing >> server and web deployment. >> http://p.sf.net/sfu/businessobjects >> _______________________________________________ >> rpy-list mailing list >> rpy-list@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/rpy-list > -- Tyler A. Erickson, Ph.D. Research Scientist, Michigan Tech Research Institute, and Adjunct Assistant Professor, Dept. of Civil & Environmental Engineering Michigan Technological University 3600 Green Court, Suite 100 Ann Arbor, MI 48105 W 83.6889°, N 42.3021° (WGS84) tyler.erick...@mtu.edu (734) 913-6846 http://people.mtri.org/tyler+erickson http://www.mtri.org http://www.michiganview.org ------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects _______________________________________________ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list