Skip to content

Commit

Permalink
version 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mponce0 authored and cran-robot committed Feb 13, 2020
1 parent 7d62553 commit 98cbd28
Show file tree
Hide file tree
Showing 20 changed files with 682 additions and 49 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
@@ -1,8 +1,8 @@
Package: bioC.logs
Type: Package
Title: BioConductor Package Downloads Stats
Version: 1.0
Date: 2020-01-30
Version: 1.1
Date: 2020-02-10
Author: Marcelo Ponce [aut, cre]
Maintainer: Marcelo Ponce <mponce@scinet.utoronto.ca>
Description: Download stats reports from the BioConductor.org stats website.
Expand All @@ -14,6 +14,6 @@ BugReports: https://github.com/mponce0/bioC.logs/issues
RoxygenNote: 6.1.99.9001
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2020-01-29 17:35:25 UTC; marcelo
Packaged: 2020-02-12 17:03:11 UTC; marcelo
Repository: CRAN
Date/Publication: 2020-02-09 16:50:09 UTC
Date/Publication: 2020-02-13 15:30:07 UTC
25 changes: 19 additions & 6 deletions MD5
@@ -1,10 +1,23 @@
db052d72f4bcfc140af23549ba03869a *DESCRIPTION
04745393c053f4bdc0ee97deb4e3c010 *NAMESPACE
88120b57df9509f28d27ed96b6537da3 *R/bioC_logs.R
5bddfb0fc14039966bc23db9a3e1b016 *README.md
cec4d32abf0e3d070a0b76b14394256f *DESCRIPTION
742ae3d1e47c80c1faf14b35923ae165 *NAMESPACE
6d593c08f881f2ef265bdab68ab34f03 *NEWS
99a5693c331121b6f5ba8e4139d53dc0 *R/auxs-utils.R
9ea96fcb093cadae59642a10cc8baafd *R/bioC_logs.R
857fe7fc8e1ff3ee0ed826625d077bcb *README.md
c24c7ae9e7bbb60722f5c5fdd6d7841c *build/vignette.rds
3c9e2d06e8560272e30c98b0c827478b *inst/doc/bioC.logs.R
5110dbd41904072d7d9d356009f9f177 *inst/doc/bioC.logs.Rmd
d3eef214a95bea5353ed7eda390e1b9c *inst/doc/bioC.logs.html
706eb66f1ed2a9b8ea80254cd78e985c *man/bioC_downloads.Rd
83e74db85b382b6011b9e5e70c8f35f8 *inst/doc/bioC.logs.html
c2542c3889883ceeb60365696d671b92 *man/Xyear.from.now.Rd
d939c259b47a3f438d210cb5127527dd *man/bioC_downloads.Rd
58b7a6c109ebcfdf9d2578aa21bed243 *man/checkDate.Rd
72e1011f8b3c82df6458a83bdb8b034a *man/checkDates.Rd
8146f5833d2382c033c3c26239e521d6 *man/checkValidDates.Rd
206ebc429371876226b03db58715041a *man/daysInMonth.Rd
b9ed70eb152c62618e6b96e65f73a867 *man/last.day.month.Rd
0fe5347f1b041d058ec053cfbc9d7180 *man/lst.year.Rd
87c66280907da3c404fb9a9f095a7ef6 *man/origin.of.times.Rd
ae5ca6247aff0015022d53fdb964bd00 *man/today.Rd
0f9e38ce24a066f6e689e4cf66c06b87 *man/year.from.now.Rd
c1b77474fcefb739d9d48ae274b09d2a *man/year.to.date.Rd
5110dbd41904072d7d9d356009f9f177 *vignettes/bioC.logs.Rmd
1 change: 1 addition & 0 deletions NAMESPACE
@@ -1,4 +1,5 @@
# Generated by roxygen2: do not edit by hand

export(bioC_downloads)
importFrom(stats,na.omit)
importFrom(utils,read.table)
2 changes: 2 additions & 0 deletions NEWS
@@ -0,0 +1,2 @@
February 2020: added options for indicating range of dates (to/from & when); adaptive last day of the month; more checks from CRAN format (remove future dates) _ ver 1.1
February 2020: First release of "bioC.logs" package _ ver 1.0
226 changes: 226 additions & 0 deletions R/auxs-utils.R
@@ -0,0 +1,226 @@
# auxs-utils.R
# -- M.Ponce


#################################################################################################
## Auxiliary Utilities file for the bioC.logs package
#
# Generic auxiliary functions
#
#################################################################################################


### date's aux fns
year.to.date <- function(){
#' function that returns the range dates for the period year-to-date
#' @keywords internal
cur.date <- Sys.Date()

cur.year <- substr(cur.date,1,4)
return(list(paste(cur.year,"01","01",sep='-'),as.character(cur.date)))
}

lst.year <- function() {
#' function that returns the range dates for the last year
#' @keywords internal
cur.date <- Sys.Date()

last.year <- as.integer(substr(cur.date,1,4))-1
return(list(paste(last.year,"01","01",sep='-'),paste(last.year+1,"01","01",sep='-')))

}

year.from.now <- function() {
#' function that returns the date from one year ago
#' @keywords internal
cur.date <- Sys.Date()
cur.year <- substr(cur.date,1,4)
lst.year <- as.integer(cur.year) - 1
t0 <- paste(lst.year,substr(cur.date,5,10),sep="")

return(list(t0,cur.date))
}

today <- function() {
#' function that returns the current date
#' @keywords internal
t1 <- Sys.Date()
# Will substract 1 to do not consider today, but yesterday
# this matches the definition from cran_downloads too
t1 <- t1 - 1
message("Ending date was not specifed, will assume today: ",t1)
return(format(t1,format="%d-%m-%Y"))
}

origin.of.times <- function() {
#' function that provides a "beginning of times" default date
#' @keywords internal
t0 <- as.Date("1980-01-01",format="%Y-%m-%d")
message("Initial date was not specified, will assume:", t0)
return(format(t0,format="%d-%m-%Y"))
}



Xyear.from.now <- function() {
#' function that returns the date from one year ago
#' @keywords internal
cur.date <- Sys.Date()-1
cur.year <- substr(cur.date,1,4)
lst.year <- as.integer(cur.year) - 1
t0 <- paste(lst.year,substr(cur.date,5,10),sep="")

message("Starting date was not specified, will assume a year from now: ",t0)
return(t0)
}

checkDates <- function(t0,t1) {
#' function to check dates, ie that t0<t1 and t0!=t1
#' @param t0 initial date
#' @param t1 final date
#' @return a list with t0 being [[1]] and t1 being [[2]]
#'
#' @keywords internal

# check if there is any missing date
if (is.null(t0)) t0 <- origin.of.times()
if (is.null(t1)) t1 <- as.Date(today(),format="%d-%b-%Y")

# check whether t0 is greater than t1
if (as.Date(t0) > as.Date(t1)) {
# flip dates, t0 will be set to the older date
ttemp <- t0
t0 <- t1
t1 <- ttemp
} else if (as.Date(t0) == as.Date(t1)) {
# dates should be different
stop(t0," and ", t1," should be different!")
}

return(list(t0,t1))
}

checkDate <- function(date.candidate) {
#' function to check date format for "MM-YYYY"
#' @param date.candidate date candidate
#'
#'
#' @keywords internal

# bisecting month and year...
MM <- as.integer(substr(date.candidate,1,2))
YYYY <- as.integer(substr(date.candidate,4,7))

if ( !is.numeric(MM) | ((MM<1) | (MM>12)) )
stop(paste("Problem detected with date: ",date.candidate,"\n","Dates should be specified in 'MM-YYYY' format, with MM from '01' to '12'"))

if (!is.numeric(YYYY))
stop(paste("Problem detected with date: ",date.candidate,"\n","Dates should be specified in 'MM-YYYY' format, with MM from '01' to '12'"))
}


checkValidDates <- function(t0,t1) {
#' function to check dates, ie that t0<t1 and t0 and t1 are in MM-YYYY format
#' @param t0 initial date
#' @param t1 final date
#' @return a list with t0 being [[1]] and t1 being [[2]]
#'
#' @keywords internal

# check date structure for t0 & t1
if (!is.null(t0)) {
checkDate(t0)
} else {
t0 <- substr(origin.of.times(),4,10)
}
if (!is.null(t1)) {
checkDate(t1)
} else {
t1 <- substr(today(),4,10)
}

fake.t0 <- as.Date(paste0("01-",t0),format='%d-%m-%Y')
fake.t1 <- as.Date(paste0("01-",t1),format='%d-%m-%Y')
#fake.t1 <- as.Date(paste0(last.day.month(

# check candidate dates
finalDates <- checkDates(fake.t0,fake.t1)

#return(list(t0,t1))
return(finalDates)
}



last.day.month <- function(MonthYear) {
#' function that returns the number of dates in a given month-year
#' @param MonthYear string containing month and year, ie. MM-YYYY
#' @return number of days --as characters-- in the given month-year
#'
#' @keywords internal

# convert year to numeric
year <- as.numeric(substr(MonthYear,5,8))
month <- substr(MonthYear,1,3)

# check for leap years
leap = FALSE
if ( (year %% 4 == 0 ) | ( year %% 100 == 0 & year %% 400 == 0) )
leap <- TRUE

# obtain number of days
nbr.days <- switch(tolower(month),
'jan' = 31,
'feb' = 28 + leap, # adds 1 if leap year
'mar' = 31,
'apr' = 30,
'may' = 31,
'jun' = 30,
'jul' = 31,
'aug' = 31,
'sep' = 30,
'oct' = 31,
'nov' = 30,
'dec' = 31 )

return(as.character(nbr.days))
}


daysInMonth <- function(d = Sys.Date()){
#' function that returns the number of dates in a given date
#' @param d string containing a date in YYYY-MM-DD format
#' @return number of days in the given the date
#'
#' @keywords internal

m = substr((as.character(d)), 6, 7) # month number as string
y = as.numeric(substr((as.character(d)), 1, 4)) # year number as numeric

# Quick check for leap year
leap = 0
if ((y %% 4 == 0 & y %% 100 != 0) | y %% 400 == 0)
leap = 1

# Return the number of days in the month
return(switch(m,
'01' = 31,
'02' = 28 + leap, # adds 1 if leap year
'03' = 31,
'04' = 30,
'05' = 31,
'06' = 30,
'07' = 31,
'08' = 31,
'09' = 30,
'10' = 31,
'11' = 30,
'12' = 31))
}



##### //////////////////////////////////////////////////////////////////////////// #####
##### //////////////////////////////////////////////////////////////////////////// #####
##### //////////////////////////////////////////////////////////////////////////// #####

0 comments on commit 98cbd28

Please sign in to comment.