Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant create file name with time stamp

Tags:

r

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??

like image 459
Marc van der Peet Avatar asked Jun 23 '15 13:06

Marc van der Peet


People also ask

How do I add timestamp to FileName?

%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.."

How do you write the time in a file name?

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.

How do you create a FileName with a date and time in python?

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.


1 Answers

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")

like image 70
Roland Avatar answered Sep 21 '22 07:09

Roland