johannes rara
2010-Oct-03 13:22 UTC
[R] Package for converting R datasets into SQL Server (create table and insert statements)?
Hi, R contains many good datasets which would be valuable in other platforms as well. My intention is to use R datasets on SQL Server as a sample tables. Is there a package that would do automatic conversion from the dataset "schema" into a SQL Server CREATE TABLE statement (and INSERT INTO statements)? For example.> str(cars)'data.frame': 50 obs. of 2 variables: $ speed: num 4 4 7 7 8 9 10 10 10 11 ... $ dist : num 2 10 4 22 16 10 18 26 34 17 ...>would become create table dbo.cars ( id int identity(1,1) not null, speed int not null, dist int not null, constraint PK_id primary key clustered (id ASC) on [PRIMARY] ) insert into dbo.cars values (N'4', N'2'), (N'4', N'10'), (N'7', N'4'), etc. -J
Eric Lecoutre
2010-Oct-05 13:26 UTC
[R] Package for converting R datasets into SQL Server (create table and insert statements)?
Hi, You can have a look at RODBC and its function sqlSave. HTH, Eric 2010/10/3 johannes rara <johannesraja@gmail.com>> Hi, > > R contains many good datasets which would be valuable in other > platforms as well. My intention is to use R datasets on SQL Server as > a sample tables. Is there a package that would do automatic conversion > from the dataset "schema" into a SQL Server CREATE TABLE statement > (and INSERT INTO statements)? > > For example. > > > str(cars) > 'data.frame': 50 obs. of 2 variables: > $ speed: num 4 4 7 7 8 9 10 10 10 11 ... > $ dist : num 2 10 4 22 16 10 18 26 34 17 ... > > > > would become > > create table dbo.cars ( > id int identity(1,1) not null, > speed int not null, > dist int not null, > constraint PK_id primary key clustered (id ASC) > on [PRIMARY] > ) > > insert into dbo.cars > values (N'4', N'2'), > (N'4', N'10'), > (N'7', N'4'), > etc. > > -J > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >-- Eric Lecoutre Consultant - Business & Decision Business Intelligence & Customer Intelligence [[alternative HTML version deleted]]