I have a file that I would to write away in a certain dir. Therefore I have the following code:
function <- {
file_path_new <- file.path("C:", "Users", "MavanderPeet", "Documents", "data")
setwd(file_path_new)
now <- Sys.time()
file_name <- paste0(now, "data_set.csv")
write.csv(data_frame, file_name)
# write.csv(data_frame, "file.csv") #for checking purposes
}
The part where I want to create a name with timestamp does not seem to work however... When I uncomment the line
write.csv(data_frame, "file.csv")
Everything works fine. So I guess it should be a syntax error....
Any thoughts??
%M. %S") echo "Current Time : $current_time" new_fileName=$file_name. $current_time echo "New FileName: " "$new_fileName" cp $file_name $new_fileName echo "You should see new file generated with timestamp on it.."
I'd use YYYY-MM-DD HHmmss for filenames, unless there is a particular need for timezones or a possible need to parse them into ISO dates; in those cases an ISO date would probably be preferrable.
For this, we will use the DateTime module. First, import the module and then get the current time with datetime. now() object. Now convert it into a string and then create a file with the file object like a regular file is created using file handling concepts in python.
The colon (:
) is not allowed in Windows file names (reference).
Use a different format:
paste0(format(now, "%Y%m%d_%H%M%S_"), "data_set.csv")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With