How to save() with a particular variable name
Just name the arguments you use. With your code the following works fine:
save(list = this.csv.data$unique_tag, file=saved_file_name)
How to save() with a particular variable name
Just name the arguments you use. With your code the following works fine:
save(list = this.csv.data$unique_tag, file=saved_file_name)
Using save() on a variable name and value connected through assign() in R
I found a solution (in a thread I unfortunately overlooked previously)
https://stat.ethz.ch/pipermail/r-help/2011-September/289404.html
Thus :
do.call(save, list(variable_name, file=paste(variable_name, "rda", sep = ".")))
@PiotrZieliński @LarsArneJordanger
R user-defined save load functions | Passing variable names as arguments using deparse(substitute)
You need to do the changes in both save
and load
functions. Use list
argument in save
function to save the data with the same variable names as passed value.
getSave <- function(folder, rdata){
val <- deparse(substitute(rdata))
save(list = val,
file = paste0("./", deparse(substitute(folder)), "/", val, ".RData"))
}
getSave(SData, x)
getSave(SData, y)
To load the data, specify the environment as global since by default the values are loaded in the called environment. Since you are loading the data in a function by default the values are loaded inside the function only.
getLoad <- function(folder, rdata){
load(paste0("./", deparse(substitute(folder)), "/", deparse(substitute(rdata)), ".RData"),
envir = .GlobalEnv)
}
getLoad(SData, x)
getLoad(SData, y)
So the issue was not related to deparse
, substitue
but how save
and load
functions work inside a user defined function.
Saving a variable as a file name and importing a function from the saved variable name - Python
You could use importlib
.
import importlib
file = input('Enter: ')
mymodule = importlib.import_module(file)
You can access variables and functions like mymodule.func1()
.
More information here
Save object using variable with object name
Try save(list=objectName, file=paste(objectName, '.Rdata', sep='') )
.
The key is that the list
argument to save
takes a list of character strings that is the names of the objects to save (rather than the actual objects passed through ...
).
Related Topics
How to Retrieve Outlook Inbox Emails Using R Rdcomclient
R Ggplot2 - How to Specify Out of Bounds Values' Colour
Converting a List of Data Frames into Individual Data Frames in R
Choropleth Map in Ggplot with Polygons That Have Holes
Spearman Correlation by Group in R
Combine Points with Lines with Ggplot2
Replace Logical Values (True/False) with Numeric (1/0)
Fixing Maps Library Data for Pacific Centred (0°-360° Longitude) Display
Dplyr - Group by and Select Top X %
Stumped on How to Scrape the Data from This Site (Using R)
Convert Character Matrix into Numeric Matrix
R Ifelse Avoiding Change in Date Format
Recode Categorical Variable to Binary (0/1)
R: How to Find the Mode of a Vector
Data.Frame Merge and Selection of Values Which Are Common in 2 Data.Frames
Stepwise Regression Using P-Values to Drop Variables with Nonsignificant P-Values