[Genabel-commits] r1772 - pkg/DatABEL/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jul 28 11:41:46 CEST 2014


Author: maksim
Date: 2014-07-28 11:41:46 +0200 (Mon, 28 Jul 2014)
New Revision: 1772

Modified:
   pkg/DatABEL/R/checkPackageVersionOnCRAN.R
Log:
Fixed version check from CRAN site

Modified: pkg/DatABEL/R/checkPackageVersionOnCRAN.R
===================================================================
--- pkg/DatABEL/R/checkPackageVersionOnCRAN.R	2014-07-25 14:29:59 UTC (rev 1771)
+++ pkg/DatABEL/R/checkPackageVersionOnCRAN.R	2014-07-28 09:41:46 UTC (rev 1772)
@@ -26,35 +26,67 @@
 checkPackageVersionOnCRAN <- function(packageName,baseUrlCRAN="http://cran.r-project.org/web/packages/", 
 		timeout = 2)
 {
-	# change default timout
-	svtmo <- options("timeout")
-	options("timeout"=timeout)
-	# page to check is
-	pageAddress <- paste(baseUrlCRAN,packageName,sep="/")
-	# establish connection to the CRAN page of the package
-	suppressWarnings(
-			conn <- try( url(pageAddress) , silent=TRUE )
-	)
-	# if connection ok, read full page, store the results in pageContent; if failed, pageContent <- "try-error"
-	if ( all( class(conn) != "try-error") ) {
-		suppressWarnings(
-				pageContent <- try( readLines(conn) , silent=TRUE )
-		)
-		close(conn)
-	} else {
-		pageContent <- "try-error"
-		class(pageContent) <- "try-error"
-	}
-	# restore default timeout
-	options("timeout"=svtmo)
-	# if failed in reading (pageContent is "try-error"), return NULL
-	if (class(pageContent) == "try-error") return(NULL)
-	# parse the page and get string starting with "Package source:"
-	targetLine <- pageContent[grep("source:",pageContent)]
-	# split the string at "Package_" and ".tar.gz"; the element before the last will contain the version
-	splitPattern <- paste(packageName,"_|.tar.gz",sep="")
-	stringSplit <- strsplit(targetLine,splitPattern)
-	cranVersion <- stringSplit[[1]][length(stringSplit[[1]])-1]
-	# return version
-	return(cranVersion)
+
+CRAN_mirror_ref <- "http://cran.xl-mirror.nl/src/contrib" # Amsterdam mirror
+
+all_cran_packs <- available.packages(contriburl=CRAN_mirror_ref)
+all_cran_packs_df <- as.data.frame(all_cran_packs)
+
+databel_info <- all_cran_packs_df[all_cran_packs_df$Package == "DatABEL",]
+cranVersion <- as.character(databel_info$Version)
+
+return(cranVersion)
+
+
+
+# Below is an old verion which depends on CRAN site content that is unreliable.
+
+#	# change default timout
+#	svtmo <- options("timeout")
+#	options("timeout"=timeout)
+#	# page to check is
+#	pageAddress <- paste(baseUrlCRAN,packageName,sep="/")
+#	# establish connection to the CRAN page of the package
+#	suppressWarnings(
+#			conn <- try( url(pageAddress) , silent=TRUE )
+#	)
+#	# if connection ok, read full page, store the results in pageContent; if failed, pageContent <- "try-error"
+#	if ( all( class(conn) != "try-error") ) {
+#		suppressWarnings(
+#				pageContent <- try( readLines(conn) , silent=TRUE )
+#		)
+#		close(conn)
+#	} else {
+#		pageContent <- "try-error"
+#		class(pageContent) <- "try-error"
+#	}
+#	# restore default timeout
+#	options("timeout"=svtmo)
+#	# if failed in reading (pageContent is "try-error"), return NULL
+#	if (class(pageContent) == "try-error") return(NULL)
+#	# parse the page and get string starting with "Package source:"
+#	targetLine <- pageContent[grep("source:",pageContent)]
+#	# split the string at "Package_" and ".tar.gz"; the element before the last will contain the version
+#	splitPattern <- paste(packageName,"_|.tar.gz",sep="")
+#	stringSplit <- strsplit(targetLine,splitPattern)
+#	cranVersion <- stringSplit[[1]][length(stringSplit[[1]])-1]
+#	# return version
+#  return(cranVersion)
+
+
+
+# Below is a patch received from Marco De Simone <marco.desimone at cbm.fvg.it>. This version is, however, use content if CRAN that is aso unreliable.
+#
+#options("timeout"=svtmo)
+## if failed in reading (pageContent is "try-error"), return NULL
+#if (class(pageContent) == "try-error") return(NULL)
+## parse the table inside the page for the cell with the content "Version:" and select the following cell that contains the version"
+#targetLine <- pageContent[grep("Version:",pageContent)+1]
+## Strip the html tags <td> and </td> and get the content value of version
+#splitPattern <- paste("<td>|</td>",sep="")
+#
+#cranVersion <- stringSplit[[1]][length(stringSplit[[1]])]
+## return version
+#return(cranVersion)
+
 }



More information about the Genabel-commits mailing list