Skip to content
Browse files

Format header line now comes first

  • Loading branch information...
1 parent 462f7f0 commit 8cbb8e5739b169f7744566525c458bf8d720d00d @jfisher-usgs committed Mar 22, 2013
View
6 NEWS
@@ -1,8 +1,12 @@
Changes in Version 0.7-4
o
-
+
o Fixed bug with finding unique values in Edit Function GUI.
+
+ o The header line specifying variable names now comes before the format
+ header line. Users need to update header lines in their input text files
+ to reflect this change.
o Measurement units have been removed. Users need to remove unit headers
from their input text files.
View
12 R/ExportData.R
@@ -14,8 +14,8 @@ ExportData <- function(col.ids, file.type="text", parent=NULL) {
tkconfigure(tt, cursor="watch")
if (file.type == "text") {
is.processed <- as.logical(as.integer(tclvalue(records.var)))
- headers <- c(as.logical(as.integer(tclvalue(head.names.var))),
- as.logical(as.integer(tclvalue(head.fmts.var))))
+ headers <- c(as.logical(as.integer(tclvalue(head.fmts.var))),
+ as.logical(as.integer(tclvalue(head.names.var))))
sep <- as.character(tclvalue(sep.var))
if (sep == "other")
sep <- as.character(tclvalue(sep.other.var))
@@ -127,8 +127,8 @@ ExportData <- function(col.ids, file.type="text", parent=NULL) {
variables.var <- tclVar()
records.var <- tclVar(0)
- head.names.var <- tclVar(0)
head.fmts.var <- tclVar(0)
+ head.names.var <- tclVar(0)
sep.var <- tclVar("\t")
sep.other.var <- tclVar()
sort.on.var <- tclVar()
@@ -229,10 +229,10 @@ ExportData <- function(col.ids, file.type="text", parent=NULL) {
frame2 <- ttklabelframe(tt, relief="flat", borderwidth=5, padding=5,
text="Include header lines")
- frame2.chk.1.1 <- ttkcheckbutton(frame2, variable=head.names.var,
- text="Names of the variables")
- frame2.chk.1.2 <- ttkcheckbutton(frame2, variable=head.fmts.var,
+ frame2.chk.1.1 <- ttkcheckbutton(frame2, variable=head.fmts.var,
text="Conversion specification formats")
+ frame2.chk.1.2 <- ttkcheckbutton(frame2, variable=head.names.var,
+ text="Names of the variables")
tkgrid(frame2.chk.1.1, frame2.chk.1.2)
tkgrid.configure(frame2.chk.1.1, padx=c(15, 15))
View
24 R/ImportData.R
@@ -88,8 +88,8 @@ ImportData <- function(parent=NULL) {
return(d)
} else {
- hds <- as.logical(c(as.integer(tclvalue(names.var)),
- as.integer(tclvalue(decis.var))))
+ hds <- as.logical(c(as.integer(tclvalue(decis.var)),
+ as.integer(tclvalue(names.var))))
RaiseWarning(tt)
if (!is.null(Data("cols"))) {
@@ -251,8 +251,8 @@ ImportData <- function(parent=NULL) {
tcl(frame4.tbl, "tag", "row", "h1", 0)
tcl(frame4.tbl, "tag", "row", "h2", 1)
- logic <- as.logical(as.integer(c(tclvalue(names.var), tclvalue(decis.var))))
- headCol <- c("#FFD0D4", "#EBFFC6")[logic]
+ logic <- as.logical(as.integer(c(tclvalue(decis.var), tclvalue(names.var))))
+ headCol <- c("#EBFFC6", "#FFD0D4")[logic]
if (length(headCol) < 2)
headCol[(length(headCol) + 1):2] <- "white"
@@ -309,9 +309,9 @@ ImportData <- function(parent=NULL) {
# Assign variables linked to Tk widgets
table.var <- tclArray()
-
- names.var <- tclVar(0)
+
decis.var <- tclVar(0)
+ names.var <- tclVar(0)
skip.var <- tclVar(0)
nrow.var <- tclVar()
source.var <- tclVar()
@@ -321,8 +321,8 @@ ImportData <- function(parent=NULL) {
# Set header variables
if (!is.null(Data("table.headers"))) {
- tclvalue(names.var) <- Data("table.headers")[1]
- tclvalue(decis.var) <- Data("table.headers")[2]
+ tclvalue(decis.var) <- Data("table.headers")[1]
+ tclvalue(names.var) <- Data("table.headers")[2]
}
# Open GUI
@@ -408,12 +408,12 @@ ImportData <- function(parent=NULL) {
frame2 <- ttklabelframe(tt, relief="flat", borderwidth=5, padding=5,
text="Header lines")
- txt <- "Names of the variables, that is, column names in the data table"
- frame2.chk.1.1 <- ttkcheckbutton(frame2, variable=names.var,
- command=SetTags, text=txt)
txt <- paste("Conversion specification formats of the variables,",
"for example, '%10.6f' or '%Y-%m-%d %H:%M'")
- frame2.chk.2.1 <- ttkcheckbutton(frame2, variable=decis.var,
+ frame2.chk.1.1 <- ttkcheckbutton(frame2, variable=decis.var,
+ command=SetTags, text=txt)
+ txt <- "Names of the variables, that is, column names in the data table"
+ frame2.chk.2.1 <- ttkcheckbutton(frame2, variable=names.var,
command=SetTags, text=txt)
tkgrid(frame2.chk.1.1, pady=1, sticky="w")
View
23 R/ReadData.R
@@ -35,18 +35,13 @@ ReadData <- function(con, headers=c(FALSE, FALSE), sep="\t",
i <- 1L
if (headers[1]) {
- nams <- as.character(h[i, ])
- nams[is.na(nams)] <- "Unknown"
- i <- i + 1L
- }
- if (headers[2]) {
fmts <- as.character(h[i, ])
# Use formats to determine column classes
n <- ncol(h)
col.classes <- rep("character", n)
- for (i in 1:n) {
- fmt <- fmts[i]
+ for (j in 1:n) {
+ fmt <- fmts[j]
test <- try(sprintf(fmt, 1), silent=TRUE)
is.error <- inherits(test, "try-error")
@@ -56,14 +51,19 @@ ReadData <- function(con, headers=c(FALSE, FALSE), sep="\t",
s <- paste(substr(fmt, 1, 1),
substr(fmt, nchar(fmt), nchar(fmt)), sep="")
if (s %in% c("%d", "%i")) {
- col.classes[i] <- "integer"
+ col.classes[j] <- "integer"
} else if (s %in% c("%f", "%e", "%E")) {
- col.classes[i] <- "numeric"
+ col.classes[j] <- "numeric"
}
}
}
}
col.classes[fmts %in% "%Y-%m-%d %H:%M:%S"] <- "POSIXct"
+ i <- i + 1L
+ }
+ if (headers[2]) {
+ nams <- as.character(h[i, ])
+ nams[is.na(nams)] <- "Unknown"
}
skip <- 0L
@@ -78,10 +78,11 @@ ReadData <- function(con, headers=c(FALSE, FALSE), sep="\t",
# Initialize missing headers
n <- ncol(d)
+
if (!headers[1])
- nams <- rep("Unknown", n)
- if (!headers[2])
fmts <- rep(NA, n)
+ if (!headers[2])
+ nams <- rep("Unknown", n)
# Reset row names
rownames(d) <- 1:nrow(d)
View
5 R/WriteFile.R
@@ -160,12 +160,13 @@ WriteFile <- function(file.type="text", file.name=NULL, col.ids=NULL,
n <- ncol(d)
h <- as.data.frame(matrix(NA, nrow=m, ncol=n))
i <- 1L
+
if (headers[1]) {
- h[i, ] <- col.nams
+ h[i, ] <- col.fmts
i <- i + 1L
}
if (headers[2])
- h[i, ] <- col.fmts
+ h[i, ] <- col.nams
write.table(h, file=con, append=FALSE, quote=FALSE, row.names=FALSE,
col.names=FALSE, sep=sep)
View
BIN data/project.rda
Binary file not shown.
View
2 inst/extdata/DataExample.csv
@@ -1,5 +1,5 @@
-T POSIXct,X numeric m,Y numeric m,Z numeric ft,Z numeric ft,Z numeric m,,Logical,Integer psia,,Logical,Date character,Time character,Character
%m/%d/%Y %H:%M:%OS,%5.1f,%5.1f,%.3f,%.2f,,%.2e,,%d,,,,,%s
+T POSIXct,X numeric m,Y numeric m,Z numeric ft,Z numeric ft,Z numeric m,,Logical,Integer psia,,Logical,Date character,Time character,Character
04/24/2009 10:43:38.275,7.8,-2.3,-0.870,998.28,-0.265,-2.62E-01,TRUE,1,,,8/20/2008,11:55:00 AM,
04/24/2009 11:20:43.757,5.0,-4.7,-1.243,998.12,-0.379,-3.70E-01,TRUE,14,,,8/20/2008,11:55:00 AM,A1
04/24/2009 12:08:31.895,2.2,-2.2,-2.362,997.65,-0.720,-6.59E-01,TRUE,6,,,8/20/2008,11:55:00 AM,A2
View
3 inst/extdata/DataExample.txt
@@ -1,8 +1,9 @@
# comment
# comment
+%m/%d/%Y %H:%M:%OS %5.1f %5.1f %.3f %.2f %.2e %d %s
+# comment
T POSIXct X numeric, m Y numeric, m Z numeric, ft Z numeric, ft Z numeric, m Logical Integer, psia Logical Date character Time character Character
# comment
-%m/%d/%Y %H:%M:%OS %5.1f %5.1f %.3f %.2f %.2e %d %s
04/24/2009 10:43:38.275 7.8 -2.3 -0.870 998.28 -0.265 -2.62E-01 TRUE 1 8/20/2008 11:55:00 AM
04/24/2009 11:20:43.757 5.0 -4.7 -1.243 998.12 -0.379 -3.70E-01 TRUE 14 8/20/2008 11:55:00 AM A1
04/24/2009 12:08:31.895 2.2 -2.2 -2.362 997.65 -0.720 -6.59E-01 TRUE 6 8/20/2008 11:55:00 AM A2
View
BIN inst/extdata/DataExample.txt.gz
Binary file not shown.
View
BIN inst/extdata/DataExample.xlsx
Binary file not shown.
View
8 man/ReadData.Rd
@@ -43,9 +43,9 @@ The imported data table requires at least two numeric variables.
\details{
This function is the primary method for importing table formatted data from
a text file. The \code{headers} argument, a logical vector of length 2,
-indicates whether the file contains the names and conversion
-specification formats of the variables as its initial lines. For example,
-\code{headers = c(TRUE, FALSE)} indicates that the first
+indicates whether the file contains the conversion specification formats and
+names of the variables as its initial lines. For example,
+\code{headers = c(FALSE, TRUE)} indicates that the first
line contains the names of variables, and no formats are included.
If \code{headers = c(FALSE, FALSE)}, the default, no header information is
contained within the file.
@@ -87,7 +87,7 @@ Sets the following components in \code{\link{Data}}:
\examples{
f <- system.file("extdata/DataExample.txt", package = "RSurvey")
con <- file(f, open = "r", encoding = "latin1")
-ans <- ReadData(con, headers = c(TRUE, TRUE, TRUE))
+ans <- ReadData(con, headers = c(TRUE, TRUE))
close(con)
}

0 comments on commit 8cbb8e5

Please sign in to comment.
Something went wrong with that request. Please try again.