|
|
@@ -32,17 +32,6 @@ charger <- function(fichier,nom=NULL,feuille=1) |
|
|
|
else if (grepl("\\.xlsx?$",fichier)) |
|
|
|
x<-read.xlsx(fichier,feuille,encoding="ISO-8859-1") |
|
|
|
|
|
|
|
if (file.exists("labels.sas")) |
|
|
|
{ |
|
|
|
con=file("labels.sas","r",encoding="ISO-8859-1") |
|
|
|
labelsfile=readLines(con) |
|
|
|
close(con) |
|
|
|
labels=labelsfile[grepl('^ *\\w*? *= *\\".*?\\" *$',labelsfile)] |
|
|
|
labels=paste(labels,collapse=",") |
|
|
|
label_exe = paste("label(x)<-c(",labels,")") |
|
|
|
eval(parse(text=label_exe)) |
|
|
|
} |
|
|
|
|
|
|
|
if (file.exists("formats.sas")) |
|
|
|
{ |
|
|
|
formats=list(0) |
|
|
@@ -51,7 +40,7 @@ charger <- function(fichier,nom=NULL,feuille=1) |
|
|
|
close(con) |
|
|
|
formatsfile=sub("^[[:space:]]*","",formatsfile) |
|
|
|
formatsfile=sub("[[:space:]]*$","",formatsfile) |
|
|
|
formatsfile=formatsfile[grepl("^value *\\w",formatsfile) | grepl("\\d* *= *\\'.*?\\'",formatsfile)] |
|
|
|
formatsfile=formatsfile[grepl("^value *\\w",formatsfile) | grepl("\\d+ *= *\\'.*?\\'",formatsfile)] |
|
|
|
formatsfile=sub("[[:space:]]*=[[:space:]]","=",formatsfile) |
|
|
|
formatsfile=sub("^(\\d+)","\\'\\1\\'",formatsfile) |
|
|
|
for (format in formatsfile) |
|
|
@@ -59,12 +48,42 @@ charger <- function(fichier,nom=NULL,feuille=1) |
|
|
|
if (grepl("^value *\\w",format)) |
|
|
|
formats[[strsplit(format," ")[[1]][2]]]<-character(0) |
|
|
|
else |
|
|
|
eval(parse(text=paste("formats[[length(formats)]]<-c(formats[[length(formats)]],",format,")",sep=""))) |
|
|
|
} |
|
|
|
formats[[1]]<-NULL |
|
|
|
if (file.exists("attribformats.sas")) |
|
|
|
{ |
|
|
|
con=file("attribformats.sas","r",encoding="ISO-8859-1") |
|
|
|
attribfile=readLines(con) |
|
|
|
close(con) |
|
|
|
attribfile=sub("^[[:space:]]*","",attribfile) |
|
|
|
attribfile=sub("[[:space:]]*$","",attribfile) |
|
|
|
attribfile=sub("\\.?$","",attribfile) |
|
|
|
attribfile=attribfile[grepl("(\\w[[:space:]]+)+format *= *\\w",attribfile)] |
|
|
|
attribfile=gsub("[[:space:]]+"," ",attribfile) |
|
|
|
attribfile=sub("[[:space:]]*=[[:space:]]","=",attribfile) |
|
|
|
for (attrib in attribfile) |
|
|
|
{ |
|
|
|
formats[[length(formats)]]<-c(formats[[length(formats)]],eval(parse(text=format))) |
|
|
|
attrib=strsplit(attrib," ")[[1]] |
|
|
|
format=strsplit(attrib[length(attrib)],"=")[[1]][2] |
|
|
|
for (var in attrib[-length(attrib)]) |
|
|
|
{ |
|
|
|
if (!is.null(x[[var]])) |
|
|
|
x[[var]]<-factor(x[[var]],levels=names(formats[[format]]),labels=formats[[format]]) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
formats[[1]]<-NULL |
|
|
|
print(formats) |
|
|
|
} |
|
|
|
|
|
|
|
if (file.exists("labels.sas")) |
|
|
|
{ |
|
|
|
con=file("labels.sas","r",encoding="ISO-8859-1") |
|
|
|
labelsfile=readLines(con) |
|
|
|
close(con) |
|
|
|
labels=labelsfile[grepl('^ *\\w*? *= *\\".*?\\" *$',labelsfile)] |
|
|
|
labels=paste(labels,collapse=",") |
|
|
|
label_exe = paste("label(x)<-c(",labels,")") |
|
|
|
eval(parse(text=label_exe)) |
|
|
|
} |
|
|
|
|
|
|
|
assign(".attachd",nom,pos=1) |
|
|
|