-
Notifications
You must be signed in to change notification settings - Fork 306
Set up R package structure and testing infrastructure #3
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ^.*\.Rproj$ | ||
| ^\.Rproj\.user$ | ||
| ^man-roxygen/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| .Rproj.user | ||
| .Rhistory | ||
| .RData | ||
| .Ruserdata | ||
| .DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| Package: tfio | ||
| Type: Package | ||
| Title: Interface to 'TensorFlow IO' | ||
| Version: 0.0.9000 | ||
| Authors@R: c( | ||
| person("Yuan", "Tang", role = c("aut", "cre"), | ||
| email = "[email protected]", | ||
| comment = c(ORCID = "0000-0001-5243-233X")), | ||
| person("TensorFlow IO SIG", role = c("aut", "cph"), | ||
| email = "[email protected]"), | ||
| person("RStudio", role = c("cph")), | ||
| person(family = "TensorFlow Authors", role = c("cph")) | ||
| ) | ||
| Description: Interface to 'TensorFlow IO', Datasets and filesystem extensions maintained by SIG-IO. | ||
| License: Apache License 2.0 | ||
| URL: https://github.com/tensorflow/io | ||
| BugReports: https://github.com/tensorflow/io/issues | ||
| SystemRequirements: TensorFlow >= 1.4 (https://www.tensorflow.org/) | ||
| Encoding: UTF-8 | ||
| LazyData: true | ||
| Depends: | ||
| R (>= 3.1) | ||
| Imports: | ||
| reticulate (>= 1.10), | ||
| tensorflow (>= 1.9), | ||
| tfdatasets (>= 1.9), | ||
| magrittr, | ||
| rlang, | ||
| tidyselect, | ||
| stats | ||
| Roxygen: list(markdown = TRUE) | ||
| RoxygenNote: 6.1.0 | ||
| Suggests: | ||
| testthat, | ||
| knitr, | ||
| tfestimators, | ||
| keras | ||
| VignetteBuilder: knitr | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Generated by roxygen2: do not edit by hand | ||
|
|
||
| export("%>%") | ||
| export(install_tensorflow) | ||
| export(tf) | ||
| export(tf_config) | ||
| import(rlang) | ||
| import(tfdatasets) | ||
| import(tidyselect) | ||
| importFrom(magrittr,"%>%") | ||
| importFrom(reticulate,import) | ||
| importFrom(reticulate,py_has_attr) | ||
| importFrom(reticulate,py_last_error) | ||
| importFrom(reticulate,py_str) | ||
| importFrom(reticulate,tuple) | ||
| importFrom(tensorflow,install_tensorflow) | ||
| importFrom(tensorflow,tf) | ||
| importFrom(tensorflow,tf_config) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| #' TensorFlow IO API for R | ||
| #' | ||
| #' This library provides an R interface to the | ||
| #' \href{https://github.com/tensorflow/io}{TensorFlow IO} API | ||
| #' that provides datasets and filesystem extensions maintained by SIG-IO. | ||
| #' | ||
| #' @docType package | ||
| #' @name tfio | ||
| NULL | ||
|
|
||
| #' @importFrom reticulate py_last_error tuple py_str py_has_attr import | ||
| #' @import tidyselect | ||
| #' @import rlang | ||
| #' @import tfdatasets | ||
| NULL | ||
|
|
||
| tfio_lib <- NULL | ||
|
|
||
| .onLoad <- function(libname, pkgname) { | ||
|
|
||
| # Delay load handler | ||
| displayed_warning <- FALSE | ||
| delay_load <- list( | ||
|
|
||
| priority = 5, | ||
|
|
||
| environment = "r-tensorflow-io", | ||
|
|
||
| on_load = function() { | ||
| check_tensorflow_version(displayed_warning) | ||
| }, | ||
|
|
||
| on_error = function(e) { | ||
| stop(tf_config()$error_message, call. = FALSE) | ||
| } | ||
| ) | ||
|
|
||
| # TODO: This is commented out for now until we add the wrappers. | ||
| # tfio_lib <<- import("tensorflow_io", delay_load = delay_load) | ||
|
|
||
| } | ||
|
|
||
| check_tensorflow_version <- function(displayed_warning) { | ||
| current_tf_ver <- tf_version() | ||
| required_least_ver <- "1.12" | ||
| if (current_tf_ver < required_least_ver) { | ||
| if (!displayed_warning) { | ||
| message("tfio requires TensorFlow version > ", required_least_ver, " ", | ||
| "(you are currently running version ", current_tf_ver, ").\n") | ||
| displayed_warning <<- TRUE | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .onUnload <- function(libpath) { | ||
|
|
||
| } | ||
|
|
||
| .onAttach <- function(libname, pkgname) { | ||
|
|
||
| } | ||
|
|
||
| .onDetach <- function(libpath) { | ||
|
|
||
| } | ||
|
|
||
| # Reusable function for registering a set of methods with S3 manually. The | ||
| # methods argument is a list of character vectors, each of which has the form | ||
| # c(package, genname, class). | ||
| registerMethods <- function(methods) { | ||
| lapply(methods, function(method) { | ||
| pkg <- method[[1]] | ||
| generic <- method[[2]] | ||
| class <- method[[3]] | ||
| func <- get(paste(generic, class, sep = ".")) | ||
| if (pkg %in% loadedNamespaces()) { | ||
| registerS3method(generic, class, func, envir = asNamespace(pkg)) | ||
| } | ||
| setHook( | ||
| packageEvent(pkg, "onLoad"), | ||
| function(...) { | ||
| registerS3method(generic, class, func, envir = asNamespace(pkg)) | ||
| } | ||
| ) | ||
| }) | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #' Pipe operator | ||
| #' | ||
| #' See \code{\link[magrittr]{\%>\%}} for more details. | ||
| #' | ||
| #' @name %>% | ||
| #' @rdname pipe | ||
| #' @keywords internal | ||
| #' @export | ||
| #' @importFrom magrittr %>% | ||
| #' @usage lhs \%>\% rhs | ||
| NULL | ||
|
|
||
| #' @importFrom tensorflow tf | ||
| #' @export | ||
| tensorflow::tf | ||
|
|
||
| #' @importFrom tensorflow install_tensorflow | ||
| #' @export | ||
| tensorflow::install_tensorflow | ||
|
|
||
| #' @importFrom tensorflow tf_config | ||
| #' @export | ||
| tensorflow::tf_config |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ## R interface to TensorFlow IO | ||
|
|
||
| This is the R interface to datasets and filesystem extensions maintained by SIG-IO. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| library(testthat) | ||
| library(tensorflow) | ||
| library(tfio) | ||
|
|
||
| test_check("tfio") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| context("TensorFlow IO dataset ops") | ||
|
|
||
| source("utils.R") | ||
|
|
||
| test_succeeds("All TensorFlow IO dataset ops work", { | ||
| print("Placeholder for now") | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| library(tensorflow) | ||
|
|
||
| skip_if_no_tensorflow <- function(required_version = NULL) { | ||
| if (!reticulate::py_module_available("tensorflow")) | ||
| skip("TensorFlow not available for testing") | ||
| else if (!is.null(required_version)) { | ||
| if (tensorflow::tf_version() < required_version) | ||
| skip(sprintf("Required version of TensorFlow (%s) not available for testing", | ||
| required_version)) | ||
| } | ||
| } | ||
|
|
||
| skip_if_no_tensorflow_io <- function(required_version = NULL) { | ||
| if (!reticulate::py_module_available("tensorflow_io")) | ||
| skip("TensorFlow not available for testing") | ||
| } | ||
|
|
||
| test_succeeds <- function(desc, expr, required_version = NULL) { | ||
| test_that(desc, { | ||
| skip_if_no_tensorflow(required_version) | ||
| expect_error(force(expr), NA) | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| Version: 1.0 | ||
|
|
||
| RestoreWorkspace: Default | ||
| SaveWorkspace: Default | ||
| AlwaysSaveHistory: Default | ||
|
|
||
| EnableCodeIndexing: Yes | ||
| UseSpacesForTab: Yes | ||
| NumSpacesForTab: 2 | ||
| Encoding: UTF-8 | ||
|
|
||
| RnwWeave: Sweave | ||
| LaTeX: pdfLaTeX | ||
|
|
||
| AutoAppendNewline: Yes | ||
| StripTrailingWhitespace: Yes | ||
|
|
||
| BuildType: Package | ||
| PackageUseDevtools: Yes | ||
| PackageInstallArgs: --no-multiarch --with-keep.source | ||
| PackageRoxygenize: rd,collate,namespace |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| --- | ||
| title: "R interface to TensorFlow IO API" | ||
| output: | ||
| rmarkdown::html_vignette: default | ||
| vignette: > | ||
| %\VignetteIndexEntry{Introduction} | ||
| %\VignetteEngine{knitr::rmarkdown} | ||
| %\VignetteEncoding{UTF-8} | ||
| type: docs | ||
| repo: https://github.com/tensorflow/io | ||
| menu: | ||
| main: | ||
| name: "Using TensorFlow IO" | ||
| identifier: "tools-tfio-using" | ||
| parent: "tfio-top" | ||
| weight: 10 | ||
| --- | ||
|
|
||
| ```{r setup, include=FALSE} | ||
| knitr::opts_chunk$set(eval = FALSE) | ||
| ``` | ||
|
|
||
| ## Overview | ||
|
|
||
| This is the R interface to datasets and filesystem extensions maintained by SIG-IO. | ||
|
|
||
| (TBA) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if for cosmetic reasons is it possible to change it to tensorflow-io to match python package?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
R package name cannot contain dashes. Also I was trying to be consistent with other existing R interfaces to TF components:
tf.estimator: https://github.com/rstudio/tfestimatorstf.dataset: https://github.com/rstudio/tfdatasets