I keep running into this frustrating error message when working with my Google Sheets script. The debugger shows ‘missing name after . operator’ and it happens specifically on line 10 of my code.
I’ve been trying to figure out what’s causing this issue but I’m stuck. The code looks correct to me but obviously something is wrong with the syntax. Has anyone encountered this before and knows how to fix it?
Here’s the code that’s giving me trouble:
function processDataFiles() {
if(!checkLibrary(tools)) {
installLibrary("tools"); checkLibrary(tools)}
loadPackage(pipes, tables)
loadLibrary(filter)
processFileWithHeader <- function(filename){
cleanName <- filename.replace(".xlsx", "");
parts <- cleanName.split("/");
sheetName <- parts[parts.length - 1];
data <- readFile(filename);
data.series_name <- sheetName;
return data;
Any help would be really appreciated!
hmm, it seems you got some R code in there. The <-
is not valid in js – you should use =
. Also, try moving that bracket from checkLibrary(tools)
to a new line. Hope this helps!
Your problem is likely due to the mix of JavaScript and R syntax. The assignment operator ‘<-’ is not valid in JavaScript; you should be using ‘=’ or variable declarations like ‘var’, ‘let’, or ‘const’ instead. I faced a similar issue when transitioning code between languages and spent quite some time debugging what looked like correct syntax. The line ‘processFileWithHeader ← function(filename){’ should be changed to ‘function processFileWithHeader(filename) {’ or ‘const processFileWithHeader = function(filename) {’. Ensure that all your other variable assignments using ‘<-’ are corrected as well. Additionally, check the placement of your brackets in the ‘checkLibrary’ line; the structure appears to be incorrect.
I ran into something very similar when I was porting some analytics code from R to Google Apps Script. The root cause is definitely the mixed syntax between the two languages. Beyond the assignment operator issue others mentioned, there are a few more problems in your code. The function declaration syntax is completely wrong for JavaScript - you cannot use ‘<-’ to assign a function like that. Also, those library loading functions at the top look like R package management commands which do not exist in Google Sheets scripting environment. You will need to rewrite this using proper JavaScript syntax throughout. Start by converting all variable assignments to use ‘=’ or proper declarations with ‘let’ or ‘const’, and change your function declaration to standard JavaScript format. The semicolon placement and bracket structure also need attention.