The tensorflow R package exposes the TensorFlow Python module through R, letting R code create tensors, run operations, compute gradients, and compile functions. section 3.3.1
Start TensorFlow from R
Load the package, select the TensorFlow backend, and create a tensor with familiar R function-call syntax. section 3.3.1
Practical translation rules shape everyday use:
- Call Python TensorFlow functions with R's $ notation, such as tf$ones() and tf$constant(). section 3.3.1
- Use zero-based indexing for Python-facing operations, append L for integer values, and use tuple() or shape() for tuple-shaped arguments. section 3.3.1
- Represent mutable model state with tf$Variable and update it using assign(), assign_add(), or R-side assignment. section 3.3.1
- Use GradientTape for derivatives, tf_function() for graph tracing, and jit_compile = TRUE for just-in-time compilation. section 3.3.1
library(tensorflow)
library(keras3)
use_backend("tensorflow")
Runnable setup for loading tensorflow and selecting the TensorFlow backend. section 3.3.1
