Skip to content

Commit

Permalink
minor changes in documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuanchao-Xu committed Nov 8, 2015
1 parent dedbd3a commit e2a93d6
Show file tree
Hide file tree
Showing 22 changed files with 147 additions and 106 deletions.
50 changes: 25 additions & 25 deletions .Rhistory
Original file line number Diff line number Diff line change
@@ -1,29 +1,4 @@
}
}
}
## For package updates information
#' @importFrom utils packageDescription
hyfoUpdates <- function(){
page <- readLines('http:https://yuanchao-xu.github.io/hyfo/')
updatesLine <- grep('id=\\"updates"', page)
versionLine <- updatesLine + 2
version <- unlist(strsplit(page[versionLine], split = ' '))[2]
version_local <- packageDescription("hyfo")$Version
# the first tow digit is the most important part of the version
version12 <- unlist(strsplit(version, split = "[.]"))[1:2]
version_local12 <- unlist(strsplit(version_local1, split = "[.]"))[1:2]
sameVersion <- version12 == version_local12
# generate message
version_msg <- strsplit(strsplit(page[versionLine], split = '<p>')[[1]][2], split = '</p>')[[1]]
infoLine <- versionLine + 2
info_msg <- strsplit(strsplit(page[infoLine], split = '<p>')[[1]][2], split = '</p>')[[1]]
install_msg <- 'You can update by type in: devtools::install_gihub("Yuanchao-Xu/hyfo")'
message_out <- NULL
if (!sameVersion) {
message_out <- paste(version_msg, info_msg, install_msg, sep = '\n')
}
return(message_out)
}
.onAttach <- function(libname, pkgname) {
message_out <- suppressWarnings(try(hyfoUpdates(), silent = TRUE))
if (!is.null(message_out)) {
Expand Down Expand Up @@ -510,3 +485,28 @@ devtools::document()
devtools::document
devtools::document()
devtools::check()
install.packages('devtools')
devtools::install_github('Yuanchao-Xu/hyfo')
library(devtools)
install_github('Yuanchao-Xu/hyfo')
library(hyfo)
?getPreciBar
b1 <- getPreciBar(tgridData, method = 'annual')
b2 <- getPreciBar(tgridData, method = 'meanMonthly')
b1 <- getPreciBar(tgridData, method = 'annual')
?getBiasFactor
devtools::document()
devtools::check()
?getPreciBar
debug(getBiasFactor)
?getBiasFactor
filePath <- system.file("extdata", "tnc.nc", package = "hyfo")
varname <- getNcdfVar(filePath)
nc <- loadNcdf(filePath, varname)
biasFactor <- getBiasFactor(nc, tgridData)
S
str(biasFactor)
biasFactor <- getBiasFactor(nc, tgridData)
debug(standardGeneric)
devtools::document()
devtools::check()
2 changes: 1 addition & 1 deletion .Rproj.user/D53FD3E6/pcs/find-in-files.pper
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"filePatterns" : [
],
"path" : "E:/1/R/hyfo/R",
"query" : "paste",
"query" : "sixto",
"regex" : false
}
}
2 changes: 1 addition & 1 deletion .Rproj.user/D53FD3E6/pcs/source-pane.pper
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"activeTab" : 3
"activeTab" : 1
}
18 changes: 18 additions & 0 deletions .Rproj.user/D53FD3E6/sdb/per/t/1608CC89
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"contents" : "#' Resample your time series or ncdf files.\n#' \n#' Resameple your time series or ncdf files, more info pleae see details.\n#' \n#' \n#' @param data a hyfo grid data or a time series, with first column date, and second column value. The date column should\n#' follow the format in \\code{as.Date}, i.e. seperate with \"-\" or \"/\". Check details for more information.\n#' @param method A string showing whether you want to change a daily data to monthly data or monthly\n#' data to daily data.e.g. \"mon2day\" and \"day2mon\".\n#' @details \n#' Note, when you want to change daily data to monthly data, a new date column will be generated,\n#' usually the date column will be the middle date of each month, 15th, or 16th. However, if your \n#' time series doesn't start from the beginning of a month or ends to the end of a month, e.g. \n#' from 1999-3-14 to 2008-2-2, the first and last generated date could be wrong. Not only the date, but also the data, because you are \n#' not calculating based on a intact month. \n#' \n#' It is a generic function, if in your case you need to debug, please see \\code{?debug()} \n#' for how to debug S4 method.\n#' \n#' @return converted time series.\n#' @examples\n#' # Daily to monthly\n#' data(testdl)\n#' TS <- testdl[[2]] # Get daily data\n#' str(TS)\n#' TS_new <- resample(TS, method = 'day2mon')\n#' \n#' # Monthly to daily\n#' TS <- data.frame(Date = seq(as.Date('1999-9-15'), length = 30, by = '1 month'), \n#' runif(30, 3, 10))\n#' TS_new <- resample(TS, method = 'mon2day')\n#' \n#' #' # First load ncdf file.\n#' filePath <- system.file(\"extdata\", \"tnc.nc\", package = \"hyfo\")\n#' varname <- getNcdfVar(filePath) \n#' nc <- loadNcdf(filePath, varname)\n#' \n#' nc_new <- resample(nc, 'day2mon')\n#' \n#' \n#' # More examples can be found in the user manual on http:https://yuanchao-xu.github.io/hyfo/\n#' \n#' @export\n#' @importFrom stats aggregate\n#' @references \n#' \n#' \\itemize{\n#' \\item R Core Team (2015). R: A language and environment for statistical computing. R Foundation for\n#' Statistical Computing, Vienna, Austria. URL http:https://www.R-project.org/.\n#' }\n#' \nsetGeneric('resample', function(data, method) {\n standardGeneric('resample')\n})\n\n\n#' @describeIn resample\nsetMethod('resample', signature('data.frame'),\n function(data, method) {\n result <- resample.TS(data, method)\n return(result)\n })\n\n#' @describeIn resample\nsetMethod('resample', signature('list'),\n function(data, method) {\n result <- resample.list(data, method)\n return(result)\n })\n\n\n\n#' @importFrom stats aggregate\nresample.TS <- function(TS, method) {\n if (length(TS) != 2) {\n stop('Time series not correct, should be two columns, Date and value.')\n } else if (!grepl('-|/', TS[1, 1])) {\n stop('First column is not date or Wrong Date formate, check the format in ?as.Date{base} \n and use as.Date to convert.')\n } \n \n \n if (method == 'mon2day') {\n \n data <- apply(TS, MARGIN = 1 , FUN = mon2day)\n \n output <- do.call('rbind', data)\n } else if (method == 'day2mon') {\n Date <- as.Date(TS[, 1])\n year <- format(Date, format = '%Y')\n mon <- format(Date, format = '%m')\n \n data <- aggregate(TS, by = list(mon, year), FUN = mean, na.rm = TRUE)[, 3:4]\n rownames(data) <- 1:dim(data)[1]\n output <- data\n } else {\n stop('method is not correct, check method argument.')\n }\n \n return (output)\n}\n\n#' @importFrom stats aggregate\nresample.list <- function(hyfo, method) {\n checkHyfo(hyfo)\n hyfoData <- hyfo$Data\n Date <- as.POSIXlt(hyfo$Dates$start)\n year <- Date$year + 1900\n mon <- Date$mon + 1\n # hyfoDim <- attributes(hyfoData)$dimensions\n # resample focuses on time dimension. No matter whether the member dimension exists.\n timeIndex <- match('time', attributes(hyfoData)$dimensions)\n dimArray <- 1:length(attributes(hyfoData)$dimensions)\n \n if (method == 'day2mon') {\n hyfoData <- apply(hyfoData, MARGIN = dimArray[-timeIndex], \n function(x) aggregate(x, by = list(mon, year), FUN = mean, na.rm = TRUE)[, 3])\n Date <- aggregate(Date, by = list(mon, year), FUN = mean, na.rm = TRUE)[, 3]\n } else if (method == 'mon2day') {\n message('Under development.')\n }\n \n hyfo$Dates$start <- Date\n hyfo$Data <- hyfoData\n return(hyfo)\n}\n\n\n\n\n#' @importFrom utils tail\n#' @references \n#' \n#' \\itemize{\n#' \\item R Core Team (2015). R: A language and environment for statistical computing. R Foundation for\n#' Statistical Computing, Vienna, Austria. URL http:https://www.R-project.org/.\n#' }\n#' \nmon2day <- function(monData) {\n Date <- as.Date(monData[1])\n data <- monData[2]\n \n DateY <- format(Date, format = '%Y')\n DateM <- format(Date, format = '%m')\n DateL <- seq(Date, length = 2, by = '1 months')[2] - Date\n \n DateD <- 1:DateL\n \n start <- as.Date(paste(DateY, DateM, DateD[1], sep = '-'))\n end <- as.Date(paste(DateY, DateM, tail(DateD, 1), sep = '-'))\n \n Date <- seq(start, end, by = '1 day')\n \n dailyData <- data.frame(Date = Date, value = rep(data, DateL))\n \n return(dailyData)\n}",
"created" : 1446994358021.000,
"dirty" : false,
"encoding" : "ASCII",
"folds" : "",
"hash" : "3185161121",
"id" : "1608CC89",
"lastKnownWriteTime" : 1446994437,
"path" : "E:/1/R/hyfo/R/resample(generic).R",
"project_path" : "R/resample(generic).R",
"properties" : {
"tempName" : "Untitled1"
},
"relative_order" : 12,
"source_on_save" : false,
"type" : "r_source"
}
17 changes: 17 additions & 0 deletions .Rproj.user/D53FD3E6/sdb/per/t/17C4CBA0

Large diffs are not rendered by default.

17 changes: 0 additions & 17 deletions .Rproj.user/D53FD3E6/sdb/per/t/44AE41D2

This file was deleted.

17 changes: 0 additions & 17 deletions .Rproj.user/D53FD3E6/sdb/per/t/45B3271

This file was deleted.

18 changes: 18 additions & 0 deletions .Rproj.user/D53FD3E6/sdb/per/t/C64EEA41

Large diffs are not rendered by default.

17 changes: 0 additions & 17 deletions .Rproj.user/D53FD3E6/sdb/per/t/DE19C258

This file was deleted.

6 changes: 3 additions & 3 deletions R/biasCorrect(generic).R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#' the value column. If the input is a hyfo dataset, the dataset should be the result of \code{loadNcdf}, or a list
#' file with the same format.
#'
#' It is a generic function, see \code{?debug()} for how to debug S4 method.
#'
#' @param frc a hyfo grid data output or a dataframe (time series) consists of Date column and one or more value columns,
#' representing the forecast to be calibrated.
Expand Down Expand Up @@ -102,7 +101,8 @@
#' It can somehow filter some extreme values caused by errors, while keep the extreme value. Seems more reasonable.
#' Better have a long period of training, and the if the forecast system is relatively stable.
#'
#'
#' It is a generic function, if in your case you need to debug, please see \code{?debug()}
#' for how to debug S4 method.
#'
#' @examples
#'
Expand Down Expand Up @@ -203,7 +203,7 @@
#' \item O. Gutjahr and G. Heinemann (2013) Comparing precipitation bias correction methods for high-resolution regional climate simulations using COSMO-CLM, Theoretical and Applied Climatology, 114, 511-529
#' }
#'
#' @author Yuanchao Xu \email{xuyuanchao37@@gmail.com }, S. Herrera \email{sixto@@predictia.es }
#' @author Yuanchao Xu \email{xuyuanchao37@@gmail.com }
#' @importFrom methods setMethod
#' @export
#'
Expand Down
5 changes: 3 additions & 2 deletions R/extractPeriod(generic).R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Extract period from list or dataframe.
#'
#' Extract common period or certain period from a list of different dataframes of time series, or from a
#' dataframe. It is a generic function, see \code{?debug()} for how to debug S4 method.
#' dataframe.
#' NOTE: all the dates in the datalist should follow the format in ?as.Date{base}.
#' @param data A list of different dataframes of time series, or a dataframe with first column Date, the rest columns value.
#' @param startDate A Date showing the start of the extract period, default as NULL, check details.
Expand Down Expand Up @@ -34,7 +34,8 @@
#' Well, if you set \code{year = 1998 : 1999}, hyfo will take month 10, 11 and 12 from year 1997, and month 1 from 1998,
#' then, take month 10, 11 and 12 from year 1998, month 1 from 1999. So you only have to care about the latter year.
#'
#'
#' It is a generic function, if in your case you need to debug, please see \code{?debug()}
#' for how to debug S4 method.
#'
#' @return A list or a dataframe with all the time series inside containing the same period.
#' @examples
Expand Down
7 changes: 6 additions & 1 deletion R/getAnnual(generic).R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' Get annual rainfall of different rainfall time series
#'
#' It is a generic function, see \code{?debug()} for how to debug S4 method.
#' Get annual rainfall of different raninfall time series.
#'
#'
#' @param data A list containing different time series of different rainfall gauges. Or a dataframe with first column Date and the rest columns the value of different
#' gauging stations. Usually an output of \code{list2Dataframe}.
Expand All @@ -12,6 +13,10 @@
#' @param ... \code{title, x, y} showing the title and x and y axis of the plot. e.g. \code{title = 'aaa'}
#' @return The annual rainfall and the number of missing data of each year and each rainfall gauge, which
#' will also be plotted. If output "mean" is seleted, the mean annual rainfall will be returned.
#' @details
#' It is a generic function, if in your case you need to debug, please see \code{?debug()}
#' for how to debug S4 method.
#'
#' @examples
#' #datalist is provided by the package as a test.
#' data(testdl)
Expand Down
7 changes: 6 additions & 1 deletion R/getPreciBar(generic).R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' get mean rainfall bar plot of the input dataset or time series.
#'
#' It is a generic function, see \code{?debug()} for how to debug S4 method.
#' get mean rainfall bar plot of the input dataset or time series.
#'
#'
#' @param data A list containing different information, should be the result of reading netcdf file using
#' \code{loadNcdf}, or load functions from \code{ecomsUDG.Raccess}, or a time series, with first column the Date, second the value.
Expand Down Expand Up @@ -37,6 +38,10 @@
#' IT IS NOT THE LONGITUDE AND LATITUDE. e.g., \code{cell = c(2, 3)}, the program will take the 2nd longitude
#' and 3rd latitude, by the increasing order. Longitude comes first.
#'
#'
#' It is a generic function, if in your case you need to debug, please see \code{?debug()}
#' for how to debug S4 method.
#'
#' @examples
#' #gridData provided by package is the result of \code{loadNcdf()}
#' data(tgridData)
Expand Down
Loading

0 comments on commit e2a93d6

Please sign in to comment.