Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions R-package/.Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
^.*\.Rproj$
^\.Rproj\.user$
^man-roxygen/
5 changes: 5 additions & 0 deletions R-package/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
.DS_Store
38 changes: 38 additions & 0 deletions R-package/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Package: tfio
Copy link
Member

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?

Copy link
Member Author

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:

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
18 changes: 18 additions & 0 deletions R-package/NAMESPACE
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)
87 changes: 87 additions & 0 deletions R-package/R/package.R
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))
}
)
})
}

23 changes: 23 additions & 0 deletions R-package/R/reexports.R
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
3 changes: 3 additions & 0 deletions R-package/README.md
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.
12 changes: 12 additions & 0 deletions R-package/man/pipe.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions R-package/man/reexports.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions R-package/man/tfio.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions R-package/tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
library(testthat)
library(tensorflow)
library(tfio)

test_check("tfio")
7 changes: 7 additions & 0 deletions R-package/tests/testthat/test-datasets-ops.R
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")
})
23 changes: 23 additions & 0 deletions R-package/tests/testthat/utils.R
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)
})
}
21 changes: 21 additions & 0 deletions R-package/tfio.Rproj
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
27 changes: 27 additions & 0 deletions R-package/vignettes/introduction.Rmd
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)