diff --git a/.Rbuildignore b/.Rbuildignore index 5e212db..b44d8ca 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1 +1,8 @@ +^\.Rhistory$ +^misc$ +^README\.Rmd$ +^appveyor\.yml$ +^\.travis\.yml$ +^RBioFormats\.Rproj$ +^\.Rproj\.user$ ^man-roxygen$ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..535bfd1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +inst/java/bioformats_package.jar +.Rhistory +.Rproj.user diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..d867cc9 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,55 @@ +# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r + +language: R +sudo: false +cache: packages +warnings_are_errors: true +use_bioc: true +bioc_required: true +cran: http://cran.rstudio.com + +addons: + apt: + packages: + - libfftw3-dev + - libgsl0-dev + - libgsl0ldbl + +os: + - linux + - osx +osx_image: xcode9 + + +env: + global: + - RGL_USE_NULL=TRUE + - DISPLAY=:99.0 +r_check_args: --as-cran --install-args=--build + +before_install: + - export PROJ_DIR=`basename $PWD` + - fname=travis_helpers.sh + - wget -O ${fname} http://bit.ly/travis_helpers + - cat ${fname}; source ${fname}; rm ${fname} + - cat DESCRIPTION + - start_xvfb ; + - export rver=`r_version`; echo $rver ; + - if [ "$TRAVIS_OS_NAME" = "osx" ]; + then + no_open_mp ; + fi + - jags_install + - export PACKAGE_NAME=`package_name` + - echo "Package Name is $PACKAGE_NAME" + - fftw_install ; + - R CMD javareconf ; + +after_success: + - cat ${PACKAGE_NAME}.Rcheck/00install.out + - cat ${PACKAGE_NAME}.Rcheck/00check.log + +after_failure: + - cat ${PACKAGE_NAME}.Rcheck/00install.out + - cat ${PACKAGE_NAME}.Rcheck/00check.log + diff --git a/DESCRIPTION b/DESCRIPTION index 548ebdc..5f57191 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,8 @@ Package: RBioFormats Version: 0.0.53 BioFormats: 5.9.2 Title: R interface to Bio-Formats -Description: An R package which interfaces the OME Bio-Formats Java library to +Description: An R package which interfaces the OME Bio-Formats + Java library to allow reading of proprietary image data and metadata. Encoding: UTF-8 Author: Andrzej OleÅ› @@ -34,4 +35,7 @@ Collate: 'utils.R' 'write.image.R' 'zzz.R' -RoxygenNote: 6.0.1 +biocViews: +RoxygenNote: 6.1.0 +BugReports: https://github.com/aoles/RBioFormats/issues +URL: https://github.com/aoles/RBioFormats diff --git a/R/zzz.R b/R/zzz.R index d36515e..0315c92 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,51 +1,56 @@ +.onAttach <- function(lib, pkg) { + + + msg <- sprintf("BioFormats library version %s", BioFormats.version()) + packageStartupMessage(msg) + +} + .onLoad <- function(lib, pkg) { + ## check whether called on a source package directory which has a different ## path to .jar files compared to the installed package (this workaround is ## needed, e.g., to run devtools::test) pkg_dir <- file.path(lib, pkg) installed <- getwd() != pkg_dir - + jar_dir <- if (installed) file.path(pkg_dir, "java") - else - jar_dir = file.path(pkg_dir, "inst", "java") - + else + jar_dir = file.path(pkg_dir, "inst", "java") + tryCatch(download_bioformats(pkg_dir, jar_dir), - error = function(e) + error = function(e) stop("failed to download Bio-Formats Java library.\n Check your internet connection and try again.", call.=FALSE) - ) - + ) + jars = if (installed) - "" - else - list.files(jar_dir, pattern = ".*\\.jar", full.names = TRUE) - + "" + else + list.files(jar_dir, pattern = ".*\\.jar", full.names = TRUE) + .jpackage(pkg, lib.loc = lib, morePaths = jars) - - msg <- sprintf("BioFormats library version %s", BioFormats.version()) - packageStartupMessage(msg) - FormatTools <<- J("loci.formats.FormatTools") } download_bioformats <- function (pkg_dir, jar_dir) { - ver <- read.dcf(file.path(pkg_dir, "DESCRIPTION"), "BioFormats") + ver <- read.dcf(file.path(pkg_dir, "DESCRIPTION"), fields = "BioFormats") jar <- "bioformats_package.jar" url_template <- "https://downloads.openmicroscopy.org/bio-formats/%s/artifacts/%s" jar_url <- sprintf(url_template, ver, jar) jar_dst <- file.path(jar_dir, jar) - + if ( file.exists(jar_dst) ) { md5_local <- tools::md5sum(jar_dst) md5_file <- readLines(paste(jar_url, "md5", sep=".")) - md5_remote <- sub("([0-9a-z]+).*", "\\1", md5_file) + md5_remote <- sub("([0-9a-z]+).*", "\\1", md5_file) if ( md5_local == md5_remote ) return(FALSE) } - + utils::download.file(jar_url, jar_dst, quiet=FALSE) - + return(TRUE) } diff --git a/RBioFormats.Rproj b/RBioFormats.Rproj new file mode 100644 index 0000000..64565bc --- /dev/null +++ b/RBioFormats.Rproj @@ -0,0 +1,22 @@ +Version: 1.0 + +RestoreWorkspace: No +SaveWorkspace: No +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: knitr +LaTeX: pdfLaTeX + +AutoAppendNewline: Yes +StripTrailingWhitespace: Yes + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source +PackageCheckArgs: --as-cran +PackageRoxygenize: rd,collate,namespace diff --git a/README.Rmd b/README.Rmd new file mode 100644 index 0000000..1f03356 --- /dev/null +++ b/README.Rmd @@ -0,0 +1,99 @@ +--- +output: github_document +--- + + + +```{r setup, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + fig.path = "man/figures/README-", + out.width = "100%" +) +``` + +```{r, include=FALSE} +if (requireNamespace("git2r")) { + repo = git2r::repository(".") + url = git2r::remote_url(repo, remote = "origin") + gh_user = basename(dirname(url)) + gh_package = basename(url) +} else { + gh_user = "aoles" + gh_package = "RBioFormats" +} +``` + +[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/`r gh_user`/`r gh_package`.svg?branch=master&svg=true)](https://ci.appveyor.com/project/`r gh_user`/`r gh_package`) +[![Travis build status](https://travis-ci.com/`r gh_user`/`r gh_package`.svg?branch=master)](https://travis-ci.com/`r gh_user`/`r gh_package`) + +## Installation + +First, make sure you have [JDK](http://www.oracle.com/technetwork/java/javase/downloads/index.html) 1.7 or higher installed. +To install *RBioFormats* use the `biocLite` installation script in order to resolve the dependency on the Bioconductor package *[EBImage](http://biocondcutor.org/packages/EBImage)*. + +```r +source("https://bioconductor.org/biocLite.R") +biocLite("aoles/RBioFormats") # You might need to first run `install.packages("devtools")` +``` + +### Mac OS X + +Mac OS comes with a legacy Apple Java 6. In order to use *RBioFormats*, you will need to update your Java installation to a newer version provided by Oracle. + +1. Install [Oracle JDK](http://www.oracle.com/technetwork/java/javase/downloads/index.html). + +2. Update R Java configuration by executing from the command line (you might have to run it as a super user by prepending `sudo` depending on your installation). +``` +R CMD javareconf +``` + +3. Re-install *rJava* from sources in order to properly link to the non-system +Java installation. +```r +install.packages("rJava", type="source") +``` + +You can verify your configuration by running the following commands. This should return the Java version string corresponding to the one downloaded and installed in step 1. + +```r +library(rJava) +.jinit() +.jcall("java/lang/System", "S", "getProperty", "java.runtime.version") +## [1] "1.8.0_112-b16" +``` + +## Documentation + +For example use, see the [package vignette](https://rawgit.com/aoles/RBioFormats/master/vignettes/RBioFormats.html). + +## FAQ + +See my [answers on Stack Overflow](http://stackoverflow.com/search?q=user:A2792099+rbioformats). + +## Caveats + +### The `java.lang.OutOfMemoryError` error + +If you get the `java.lang.OutOfMemoryError: Java heap space` error, try increasing the maximum heap size by supplying the -Xmx parameter before the Java Virtual Machine is initialized. For example, use + +```r +options( java.parameters = "-Xmx4g" ) +library( "RBioFormats" ) +``` + +to override the default setting and assign 4 gigabytes of heap space to the Java environment. + +Information about the current Java heap space limit can be retrieved by `checkJavaMemory()`. + +### Use with BiocParallel + +Each R process needs a separate JVM instance. For this, load the package in the parallelized function, e.g., + +```r +bplapply (files, function(f) { + library(RBioFormats) + ... +}) +``` diff --git a/README.md b/README.md index 210e293..fe3d90c 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,56 @@ + + + +[![AppVeyor build +status](https://ci.appveyor.com/api/projects/status/github/muschellij2/RBioFormats.svg?branch=master&svg=true)](https://ci.appveyor.com/project/muschellij2/RBioFormats) +[![Travis build +status](https://travis-ci.com/muschellij2/RBioFormats.svg?branch=master)](https://travis-ci.com/muschellij2/RBioFormats) + ## Installation -First, make sure you have [JDK](http://www.oracle.com/technetwork/java/javase/downloads/index.html) 1.7 or higher installed. -To install *RBioFormats* use the `biocLite` installation script in order to resolve the dependency on the Bioconductor package *[EBImage](http://biocondcutor.org/packages/EBImage)*. +First, make sure you have +[JDK](http://www.oracle.com/technetwork/java/javase/downloads/index.html) +1.7 or higher installed. To install *RBioFormats* use the `biocLite` +installation script in order to resolve the dependency on the +Bioconductor package +*[EBImage](http://biocondcutor.org/packages/EBImage)*. -```r +``` r source("https://bioconductor.org/biocLite.R") biocLite("aoles/RBioFormats") # You might need to first run `install.packages("devtools")` ``` ### Mac OS X -Mac OS comes with a legacy Apple Java 6. In order to use *RBioFormats*, you will need to update your Java installation to a newer version provided by Oracle. +Mac OS comes with a legacy Apple Java 6. In order to use *RBioFormats*, +you will need to update your Java installation to a newer version +provided by Oracle. -1. Install [Oracle JDK](http://www.oracle.com/technetwork/java/javase/downloads/index.html). +1. Install [Oracle + JDK](http://www.oracle.com/technetwork/java/javase/downloads/index.html). -2. Update R Java configuration by executing from the command line (you might have to run it as a super user by prepending `sudo` depending on your installation). -``` -R CMD javareconf -``` +2. Update R Java configuration by executing from the command line (you + might have to run it as a super user by prepending `sudo` depending + on your installation). + + + + R CMD javareconf + +3. Re-install *rJava* from sources in order to properly link to the + non-system Java installation. + + -3. Re-install *rJava* from sources in order to properly link to the non-system -Java installation. -```r +``` r install.packages("rJava", type="source") ``` -You can verify your configuration by running the following commands. This should return the Java version string corresponding to the one downloaded and installed in step 1. +You can verify your configuration by running the following commands. +This should return the Java version string corresponding to the one +downloaded and installed in step 1. -```r +``` r library(rJava) .jinit() .jcall("java/lang/System", "S", "getProperty", "java.runtime.version") @@ -36,32 +59,39 @@ library(rJava) ## Documentation -For example use, see the [package vignette](https://rawgit.com/aoles/RBioFormats/master/vignettes/RBioFormats.html). +For example use, see the [package +vignette](https://rawgit.com/aoles/RBioFormats/master/vignettes/RBioFormats.html). ## FAQ -See my [answers on Stack Overflow](http://stackoverflow.com/search?q=user:A2792099+rbioformats). +See my [answers on Stack +Overflow](http://stackoverflow.com/search?q=user:A2792099+rbioformats). ## Caveats ### The `java.lang.OutOfMemoryError` error -If you get the `java.lang.OutOfMemoryError: Java heap space` error, try increasing the maximum heap size by supplying the -Xmx parameter before the Java Virtual Machine is initialized. For example, use +If you get the `java.lang.OutOfMemoryError: Java heap space` error, try +increasing the maximum heap size by supplying the -Xmx parameter before +the Java Virtual Machine is initialized. For example, use -```r +``` r options( java.parameters = "-Xmx4g" ) library( "RBioFormats" ) ``` -to override the default setting and assign 4 gigabytes of heap space to the Java environment. +to override the default setting and assign 4 gigabytes of heap space to +the Java environment. -Information about the current Java heap space limit can be retrieved by `checkJavaMemory()`. +Information about the current Java heap space limit can be retrieved by +`checkJavaMemory()`. ### Use with BiocParallel -Each R process needs a separate JVM instance. For this, load the package in the parallelized function, e.g., +Each R process needs a separate JVM instance. For this, load the package +in the parallelized function, e.g., -```r +``` r bplapply (files, function(f) { library(RBioFormats) ... diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..b574918 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,54 @@ +# DO NOT CHANGE the "init" and "install" sections below + +# Download script file from GitHub +init: + ps: | + $ErrorActionPreference = "Stop" + Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" + Import-Module '..\appveyor-tool.ps1' + +install: + ps: Bootstrap + +cache: + - C:\RLibrary + +platform: x64 + +environment: + global: + USE_RTOOLS: true + R_CHECK_ARGS: "--no-multiarch --no-manual --as-cran" + WARNINGS_ARE_ERRORS: 1 + R_ARCH: x64 + +# Adapt as necessary starting from here + +build_script: + - Rscript -e "install.packages('rJava', type = 'source', repos=c(CRAN='https://cran.rstudio.com'))" + - travis-tool.sh install_deps + +test_script: + - travis-tool.sh run_tests +on_failure: + - 7z a failure.zip *.Rcheck\* + - appveyor PushArtifact failure.zip + +after_test: +- 7z a testthat.zip *.Rcheck\**\*.Rout + +artifacts: + - path: '*.Rcheck\**\*.log' + name: Logs + + - path: '*.Rcheck\**\*.out' + name: Logs + + - path: '*.Rcheck\**\*.fail' + name: Logs + + - path: testthat.zip + name: Logs + + - path: '\*_*_*.zip' + name: Bits diff --git a/cleanup b/cleanup new file mode 100755 index 0000000..64fc02a --- /dev/null +++ b/cleanup @@ -0,0 +1,2 @@ +#!/bin/bash +rm -rf inst/java/bioformats_package.jar \ No newline at end of file diff --git a/man/read.metadata.Rd b/man/read.metadata.Rd index 4fc285c..181da32 100644 --- a/man/read.metadata.Rd +++ b/man/read.metadata.Rd @@ -4,7 +4,8 @@ \alias{read.metadata} \title{Read Image Metadata} \usage{ -read.metadata(file, filter.metadata = FALSE, proprietary.metadata = TRUE) +read.metadata(file, filter.metadata = FALSE, + proprietary.metadata = TRUE) } \arguments{ \item{file}{character, file name}