This function uses python to perform transformations of the input matrix
A numeric R matrix.
Boolean. Whether the matrix needs to be transposed. If starting with samples as columns, set to TRUE. Default is FALSE
Boolean. Whether to center and scale the matrix. Default to TRUE
Character. The backend which to use for performing transformations. Default is "rtorch". Options are "r", "rtorch", or "pytorch". See details for information about the pytorch/conda environments
Numeric. The number of cores to use.
A matrix that has been rotated (transposed) and scaled if needed
Depending on the backend chosen, the session may need to be reset with rstudioapi::restartSession().
Mainly, this is due to conflicts between some underlying system level variables with 'rtorch' and 'pytorch'.
Once one is used in a session, the other will fail. Even testing using 'rtorch' and then starting the conda environment
resulted in the environment being loaded by the python libraries/modules are not available. Unless absolutely needed
and for testing, would stick with 'rtorch'
if (FALSE) { # \dontrun{
#need to have environment first
reticulate::use_condaenv("FastPCA")
# Create a sample R matrix (e.g., 20 samples, 100 features)
# Ensure values are positive for log transform.
set.seed(123)
test_data <- matrix(runif(20 * 100, min=1, max=100), nrow = 20, ncol = 100)
colnames(test_data) <- paste0("Feature", 1:ncol(test_data))
rownames(test_data) <- paste0("Sample", 1:nrow(test_data))
print(paste("Original R matrix dimensions:", paste(dim(test_data), collapse = "x")))
# Perform Randomized SVD
prepped_matrix <- FastPCA::prep_matrix(test_data, log2 = TRUE,
transpose = FALSE, scale = TRUE)
} # }