haotu : an open lab notebook

2016/06/24

save rda data file with compression

Filed under: errors in R, R, R, R Stats — Tags: , , , , — S @ 06:36
save(mydata,file="mydata.rda",compress="xz")

find non-ascii in R

Filed under: errors in R, R, R, R Stats, Uncategorized — Tags: , , , , — S @ 06:34
tools::showNonASCII(readLines("myfiles.R"))

2016/06/23

Add timestamp to Google Sheets when data are entered

Filed under: Google, Google Docs, Sheets — Tags: , , — S @ 07:03

I wanted a time/date stamp for when a particular cell was populated with data.

First you will need to open the Script editor under Tools. Then paste and edit the below code.

 

function onEdit(event) { 
 var timezone = "GMT-4"; 
 var timestamp_format = "MM-dd-yyyy HH:mm"; // Timestamp Format. 
 var updateColName = "value"; // Column where data are populated
 var timeStampColName = "Timestamp"; // Column where timestamp is automatically populated
 var sheet = event.source.getSheetByName("data"); //Name of the sheet where you want to run this script. 
 var actRng = event.source.getActiveRange(); 
 var editColumn = actRng.getColumn(); 
 var index = actRng.getRowIndex(); 
 var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues(); 
 var dateCol = headers[0].indexOf(timeStampColName); 
 var updateCol = headers[0].indexOf(updateColName); updateCol = updateCol+1; 
 if (dateCol > -1 && index > 1 && editColumn == updateCol) { // only timestamp if 'Timestamp' header exists, but not in the header row itself! 
 var cell = sheet.getRange(index, dateCol + 1); 
 var date = Utilities.formatDate(new Date(), timezone, timestamp_format); 
 cell.setValue(date); } 
}


See here for original code as well as a video

Note that if you run the script (hit Play button) in the script editor you will get an error on line 6 simply because the “event” cannot be called in the editor. The code should still work fine.

Create a free website or blog at WordPress.com.