Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making amenable to R CMD check #15

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
7 changes: 7 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
^\.Rhistory$
^misc$
^README\.Rmd$
^appveyor\.yml$
^\.travis\.yml$
^RBioFormats\.Rproj$
^\.Rproj\.user$
^man-roxygen$
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
inst/java/bioformats_package.jar
.Rhistory
.Rproj.user
55 changes: 55 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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

8 changes: 6 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
<https://www.openmicroscopy.org/bio-formats/> Java library to
allow reading of proprietary image data and metadata.
Encoding: UTF-8
Author: Andrzej Oleś
Expand Down Expand Up @@ -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
45 changes: 25 additions & 20 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -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)
}
22 changes: 22 additions & 0 deletions RBioFormats.Rproj
Original file line number Diff line number Diff line change
@@ -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
99 changes: 99 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
output: github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{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)
...
})
```
Loading