Commit 42e84521 authored by Jean-Marie Lepioufle's avatar Jean-Marie Lepioufle
Browse files

put on gitlab

parents
^.*\.Rproj$
^\.Rproj\.user$
.Rproj.user
.Rhistory
.RData
Package: frostlyr
Type: Package
Version: 0.0.1
Authors@R: c(person("Jean-Marie", "Lepioufle", , "jml@nilu.no", role=c("aut","cre")),
person("NILU",role="cph"))
Title: frostlyr
Description: Make frost dataset easy to manipulate.
The package provides:
1. libraries to access frost api.
2. get friendly data.frame to work with.
Depends:
R (>= 3.2.0)
Imports:
frostr,
timelyr,
timemanip
Remotes: git::git@git.nilu.no:rextapi/frostr.git,
git::git@git.nilu.no:rfriendlyr/timelyr.git,
git::git@git.nilu.no:rspacetimemanip/timemanip.git
License: GPL-3
Encoding: UTF-8
LazyData: false
RoxygenNote: 5.0.1
# Generated by roxygen2: do not edit by hand
export(frostly_friendly)
export(frostlyr_df_data)
export(frostlyr_df_qa)
export(frostlyr_get_data)
export(frostlyr_get_meta)
export(frostlyr_get_qa)
#' frostlyr_df_data
#' frostlyr_df_data
#' @param x request object
#' @param res resulted data.frame
#' @keywords frostlyr
#' @export
#' @examples
#' \dontrun{
#' frostlyr_df_data()
#' }
frostlyr_df_data <- function(x,res){
tmp <- df_data(x=x,ugly_df=res,target="value")
if (x$dateStructObj$COL_DATE) {
# ..
} else if (!x$dateStructObj$COL_DATE){
tmp <- timelyr::checkDate(df = tmp, timeObj=x$timeObj, missingValues = NA,date_col="date",date_type="posixlt")
} else stop("COL_DATE in the right format")
return(tmp)
}
#' frostlyr_df_qa
#' frostlyr_df_qa
#' @param x request object
#' @param res resulted data.frame
#' @keywords frostlyr
#' @export
#' @examples
#' \dontrun{
#' frostlyr_df_qa()
#' }
frostlyr_df_qa <- function(x,res){
tmp <- df_data(x=x,ugly_df=res,target="qualityCode")
names(tmp) <- c(names(tmp)[1],paste0("qa_",names(tmp)[-1]))
if (x$dateStructObj$COL_DATE) {
# ..
} else if (!x$dateStructObj$COL_DATE){
tmp <- timelyr::checkDate(df = tmp, timeObj=x$timeObj, missingValues = NA,date_col="date",date_type="posixlt")
} else stop("COL_DATE in the right format")
return(tmp)
}
df_data <- function(x,ugly_df,target){
output <- data.frame(date = x$timeObj$seqPeriod())
for (i_e in 1:length(x$elementObj$element_id)) {
if (length(x$stationObj$station_id)>0) {
indice <- NULL
i_s <- 0
while ( (!length(indice)) && (i_s< length(x$stationObj$station_id))) {
i_s <- i_s+1
indice <- which( (ugly_df["ID"] == x$stationObj$station_id[i_s]) & (ugly_df["CO_NAME"] == x$elementObj$element_id[i_e]))
}
stations_id <- x$stationObj$station_id[i_s]
tmp <- timelyr::checkDate(df=ugly_df[indice,],timeObj = x$timeObj, missingValues=NA,date_col="date",date_type="char_iso8601")[,target]
df <- tmp
if (length(x$stationObj$station_id)>1) {
while (i_s< length(x$stationObj$station_id)) {
indice <- NULL
while ( (!length(indice)) && (i_s< length(x$stationObj$station_id))) {
i_s <- i_s+1
indice <- which( (ugly_df["ID"] == x$stationObj$station_id[i_s]) & (ugly_df["CO_NAME"] == x$elementObj$element_id[i_e]))
}
stations_id <- c(stations_id,x$stationObj$station_id[i_s])
tmp <- timelyr::checkDate(df=ugly_df[indice,],timeObj = x$timeObj, missingValues=NA,date_col="date",date_type="char_iso8601")[,target]
df <- cbind(df,tmp)
}
}
output$element <- data.frame(df)
colnames(output$element) <- (stations_id)
}
colnames(output) <- c("date",x$elementObj$element_id[1:i_e])
}
# flatten the multi-data.frame
return(timelyr::flatten(output))
}
#' frostly_friendly
#' frostly_friendly
#' @param fn character fun
#' @param type character type
#' @keywords frostly
#' @export
#' @examples
#' \dontrun{
#' frostly_friendly()
#' }
frostly_friendly <- function(fn,type) {
return(get(paste0("frostly_",fn,"_",type)))
}
#' frostlyr_get_data
#' frostlyr_get_data
#' @param x request object
#' @param username username
#' @param password password
#' @keywords frostlyr
#' @export
#' @examples
#' \dontrun{
#' frostlyr_get_data()
#' }
frostlyr_get_data <- function(x,username=NULL,password=NULL) {
api <- frostr::api(httpauth = 1,userpwd=paste0(username,":",password))
if (!is.null(x$stationObj$locationName)){
meta <- frostlyr_get_meta(x=x,username=username,password=password)
station_id <- meta$ID
} else if (!is.null(x$stationObj$station_id)) {
station_id <- x$stationObj$station_id
}
from <- timemanip::posixlt2char(x$timeObj$fromDateTime(),ISO8601=TRUE)
to <- timemanip::posixlt2char(x$timeObj$toDateTime(),ISO8601=TRUE)
referencetime <- paste0(from,"/",to)
res <- frostr::get_short_data(frostObj=api,stations=station_id,referencetime=referencetime,elements=x$elementObj$element_id)
return(res)
}
#' frostlyr_get_meta
#' frostlyr_get_meta
#' @param x request object
#' @param username username
#' @param password password
#' @keywords frostlyr
#' @export
#' @examples
#' \dontrun{
#' frostlyr_get_meta()
#' }
frostlyr_get_meta <- function(x,username=NULL,password=NULL) {
api <- frostr::api(httpauth = 1,userpwd=paste0(username,":",password))
res <- frostr::get_short_meta_station_with_element(frostObj=api,stations=x$stationObj$station_id,west=x$stationObj$west,south=x$stationObj$south,east=x$stationObj$east,north=x$stationObj$north,elements=x$elementObj$element_id)
return(res)
}
#' frostlyr_get_qa
#' frostlyr_get_qa
#' @param x request object
#' @param username username
#' @param password password
#' @keywords frostlyr
#' @export
#' @examples
#' \dontrun{
#' frostlyr_get_qa()
#' }
frostlyr_get_qa <- function(x,username=NULL,password=NULL) {
stop("qa gathering not implemented")
}
# frostlyr
## Description
frostlyr deals with getting frost dataset as a timeserie data.frame easy to work with.
## Prerequisite
Install the "remotes" R-package
```R
source("https://raw.githubusercontent.com/r-lib/remotes/master/install-github.R")$value("r-lib/remotes")
```
## Installation
```R
library("remotes")
remotes::install_git("git@git.nilu.no:rfriendlyr/frostlyr.git")
```
Version: 1.0
RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
Encoding: UTF-8
AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/frostlyr_friendly.R
\name{frostly_friendly}
\alias{frostly_friendly}
\title{frostly_friendly
frostly_friendly}
\usage{
frostly_friendly(fn, type)
}
\arguments{
\item{fn}{character fun}
\item{type}{character type}
}
\description{
frostly_friendly
frostly_friendly
}
\examples{
\dontrun{
frostly_friendly()
}
}
\keyword{frostly}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/frostlyr_df.R
\name{frostlyr_df_data}
\alias{frostlyr_df_data}
\title{frostlyr_df_data
frostlyr_df_data}
\usage{
frostlyr_df_data(x, res)
}
\arguments{
\item{x}{request object}
\item{res}{resulted data.frame}
}
\description{
frostlyr_df_data
frostlyr_df_data
}
\examples{
\dontrun{
frostlyr_df_data()
}
}
\keyword{frostlyr}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/frostlyr_df.R
\name{frostlyr_df_qa}
\alias{frostlyr_df_qa}
\title{frostlyr_df_qa
frostlyr_df_qa}
\usage{
frostlyr_df_qa(x, res)
}
\arguments{
\item{x}{request object}
\item{res}{resulted data.frame}
}
\description{
frostlyr_df_qa
frostlyr_df_qa
}
\examples{
\dontrun{
frostlyr_df_qa()
}
}
\keyword{frostlyr}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/frostlyr_get.R
\name{frostlyr_get_data}
\alias{frostlyr_get_data}
\title{frostlyr_get_data
frostlyr_get_data}
\usage{
frostlyr_get_data(x, username = NULL, password = NULL)
}
\arguments{
\item{x}{request object}
\item{username}{username}
\item{password}{password}
}
\description{
frostlyr_get_data
frostlyr_get_data
}
\examples{
\dontrun{
frostlyr_get_data()
}
}
\keyword{frostlyr}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/frostlyr_get.R
\name{frostlyr_get_meta}
\alias{frostlyr_get_meta}
\title{frostlyr_get_meta
frostlyr_get_meta}
\usage{
frostlyr_get_meta(x, username = NULL, password = NULL)
}
\arguments{
\item{x}{request object}
\item{username}{username}
\item{password}{password}
}
\description{
frostlyr_get_meta
frostlyr_get_meta
}
\examples{
\dontrun{
frostlyr_get_meta()
}
}
\keyword{frostlyr}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/frostlyr_get.R
\name{frostlyr_get_qa}
\alias{frostlyr_get_qa}
\title{frostlyr_get_qa
frostlyr_get_qa}
\usage{
frostlyr_get_qa(x, username = NULL, password = NULL)
}
\arguments{
\item{x}{request object}
\item{username}{username}
\item{password}{password}
}
\description{
frostlyr_get_qa
frostlyr_get_qa
}
\examples{
\dontrun{
frostlyr_get_qa()
}
}
\keyword{frostlyr}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment