Skip to content

Commit

Permalink
Merge pull request #24 from scizmeli/dev
Browse files Browse the repository at this point in the history
Baris please pull Tasks/Defects 8744 8854 and 8761
  • Loading branch information
yilmazbrs authored Mar 15, 2017
2 parents 8436cdc + 06afe2f commit 62c0046
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 83 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: geoSpectral
Type: Package
Title: Classes and methods for spectral (optical) data
Title: Classes and methods for working with spectral (electromagnetic) data in R.
Version: 0.11
Date: 2012-07-02
Depends:
Expand Down
43 changes: 18 additions & 25 deletions R/Spectra-Class.R
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
# TODO: Add comment
#
# Author: acizmeli
###############################################################################
#########################################################################
# Class : Spectra
#########################################################################
#' Create a spectra class definition
#' @description
#' Create a spectra class definition, specifying the representation (the slots) and/or the classes contained in this one (the superclasses),
#' plus other optional details. As a side effect, the class definition is stored in the specified environment
#'
#' @usage
#' setClass(class, contains,pepresentation,prototype)
#'
#'
#'
#'
#' @param contains STIDF
#' @param class character string name for the class.
#' @param pepresentation avoided
#' @param prototype n object providing the default data for the slots in this class
#'
#'
#'
#'
#'
#'
#'
#'
#' Spectra class is the main class provided by the package geoSpectRal. It allows storage
#' of spectral or non-spectra data with space and time attributes.
#' @slot ShortName character, A short name for the parameter described in the spectra object.
#' @slot LongName character, A long name for the parameter described in the spectra object.
#' @slot Spectra matrix, n by m matrix, describing n rows of spectral data
#' (or time) in m channels (columns).
#' @slot data data.frame n by t data frame, describind n rows of ancillary data
#' of t variables. This slot is inherited from STIDF class.
#' @slot Wavelengths numeric vector, length of m. Wavelength data.
#' @slot WavelengthsUnit character, Units of the @Wavelength slot
#' @slot header SpcHeader, Header object. See SpcHeader-class.
#' @slot Units character, Units of spectral data.
#' @slot UnitsAnc character, Units of each column of the @data slot holding ancillary data.
#' @slot ShortNameAnc character, A short name for each column of the @data slot holding ancillary data.
#' @slot LongNameAnc character, A long name for each column of the @data slot holding ancillary data.
#' @slot InvalidIdx logical, length of m. Row index for measurements marked by the user as invalid.
#' @slot SelectedIdx logical, length of m. Row index for measurements marked by the user as selected.
#' @slot ClassVersion numeric, Version of the class.
setClass("Spectra", contains="STIDF",
representation=representation(
ShortName="character",
Expand Down
84 changes: 45 additions & 39 deletions R/Spectra-Methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -1993,54 +1993,60 @@ spc.header.infos = function(header){
#'
#'@details
#' \code{spc.export.xlsx()} calls functions from package \code{xlsx} to write the contents of
#' a \code{Spectra} object into an Excel file.
#' a \code{Spectra} object into an Excel file. Make sure \code{xlsx} is installed.
#'
#' @return None. Simply creates an Excel file on disk.
#'
#' @examples
#' sp=spc.example_spectra()
#' if("xlsx" %in% installed.packages())
#' spc.export.xlsx(sp,"test.xlsx")
#' \dontrun{
#' sp=spc.example_spectra()
#' if("xlsx" %in% installed.packages())
#' spc.export.xlsx(sp,"test.xlsx")
#' }
setGeneric(name="spc.export.xlsx",
def=function(input,filename,sheetName,writeheader=TRUE,append=F,sep=";",...) {standardGeneric("spc.export.xlsx")})
setMethod("spc.export.xlsx", signature="Spectra", definition=function(input,filename,sheetName,writeheader,append,sep,...){
if(missing(sheetName))
sheetName = input@ShortName
data = as(input,"data.frame")
data$TIME = as.character(data$TIME,usetz=TRUE)
data$ENDTIME = as.character(data$ENDTIME,usetz=TRUE)
data = cbind(data.frame(idx=1:nrow(data)),data)

slotInfos = .spc.slot.infos(input,sep)
if(!append){
#Create an empty excel workbook and start writing into it
wb <- xlsx::createWorkbook()
}else{
#Create an empty excel workbook and start writing into it
wb <- xlsx::loadWorkbook(file=filename)
}
sheet <- xlsx::createSheet(wb, sheetName=sheetName)
if(writeheader){
for(I in 1:length(input@header)){
if(length(input@header[[I]])==1)
myH=cbind("Spectra|header",names(input@header)[I],input@header[[I]])
else
myH = cbind("Spectra|header",names(input@header)[I],t(input@header[[I]]))
xlsx::addDataFrame(myH, sheet,row.names=F,col.names=F,,startRow=I,startColumn=1)
if (!requireNamespace("xls", quietly = TRUE)) {
print("xlsx needed for this function to work. Please install it.")
} else {
if(missing(sheetName))
sheetName = input@ShortName
data = as(input,"data.frame")
data$TIME = as.character(data$TIME,usetz=TRUE)
data$ENDTIME = as.character(data$ENDTIME,usetz=TRUE)
data = cbind(data.frame(idx=1:nrow(data)),data)

slotInfos = .spc.slot.infos(input,sep)
if(!append){
#Create an empty excel workbook and start writing into it
wb <- xlsx::createWorkbook()
}else{
#Create an empty excel workbook and start writing into it
wb <- xlsx::loadWorkbook(file=filename)
}
sheet <- xlsx::createSheet(wb, sheetName=sheetName)
if(writeheader){
for(I in 1:length(input@header)){
if(length(input@header[[I]])==1)
myH=cbind("Spectra|header",names(input@header)[I],input@header[[I]])
else
myH = cbind("Spectra|header",names(input@header)[I],t(input@header[[I]]))
xlsx::addDataFrame(myH, sheet,row.names=F,col.names=F,,startRow=I,startColumn=1)
}
}
written = length(input@header)
for(I in 1:length(slotInfos)){
if(length(slotInfos[[I]])==1)
mysl=cbind(names(slotInfos)[I],slotInfos[[I]])
else
mysl = cbind(names(slotInfos)[I],t(slotInfos[[I]]))
xlsx::addDataFrame(mysl,sheet,row.names=F,col.names=F,startRow=written+1,startColumn=1)
written = written+1
}
xlsx::addDataFrame(data, sheet,row.names=F,startRow=written+1,startColumn=1)
xlsx::saveWorkbook(wb, filename)
print(paste("Wrote sheet", sheetName, "to", filename))
}
written = length(input@header)
for(I in 1:length(slotInfos)){
if(length(slotInfos[[I]])==1)
mysl=cbind(names(slotInfos)[I],slotInfos[[I]])
else
mysl = cbind(names(slotInfos)[I],t(slotInfos[[I]]))
xlsx::addDataFrame(mysl,sheet,row.names=F,col.names=F,startRow=written+1,startColumn=1)
written = written+1
}
xlsx::addDataFrame(data, sheet,row.names=F,startRow=written+1,startColumn=1)
xlsx::saveWorkbook(wb, filename)
print(paste("Wrote sheet", sheetName, "to", filename))
})

#########################################################################
Expand Down
2 changes: 1 addition & 1 deletion R/geoSpectral.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @title Manipulation of spectral (electromagnetic) data
#' @title Classes and methods for working with spectral (electromagnetic) data in R.
#'
#' @description
#' \pkg{geoSpectral} is an R package providing a new data type for R that stores
Expand Down
46 changes: 34 additions & 12 deletions man/Spectra-class.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/geoSpectral.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions man/spc.export.xlsx.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 62c0046

Please sign in to comment.