I keep running into this syntax error when I execute my Google Sheets script:
name expected after dot operator
The error appears on line 10 during script execution. I’ve checked the syntax multiple times but can’t figure out what’s causing this issue. Has anyone encountered this before and found a solution?
yeah, that’s definitely R code mixed with javascript. google sheets script engine doesn’t recognize replaceText() or the pipe operator %>%. use filename.replace('.csv', '') and cleanName.split('/') instead. also, that arrow function syntax on line 9 won’t work in apps script.
The problem is you’re mixing R syntax with Google Apps Script, which uses JavaScript. Line 10 fails because JavaScript doesn’t know what replaceText is - that’s R code.
I’ve hit this same wall moving R scripts to Google Sheets. JavaScript handles variables and methods differently. You need let or var for variables, and string methods work directly on the string.
Fix line 10 with filename.replace(".csv", "") instead of replaceText(). Line 11 needs split("/") - ditch the pipe operator. JavaScript arrays start at zero, so grab the last element with parts[parts.length - 1].
One more thing - Google Apps Script has tons of built-in functions for Sheets. You might not need custom file reading at all. Check their docs first - could save you a lot of work.
Your code’s mixing R and JavaScript syntax - that’s what’s breaking it. Google Apps Script runs JavaScript, not R.
Line 10: replaceText doesn’t exist in JavaScript. Use replace() instead.
Line 11: That %>% pipe operator is R syntax. JavaScript won’t recognize it.
Line 12: You’re accessing parts.length wrong.
Here’s the fixed JavaScript:
function processDataFiles() {
// Your setup code here
}
function process_file_data(filename) {
let cleanName = filename.replace(".csv", "");
let parts = cleanName.split("/");
let category = parts[parts.length - 1];
// Process your data here
return data;
}
Honestly, debugging syntax issues and managing Google Sheets automations gets old fast. I’ve switched to using Latenode for similar workflows.
Latenode lets you build visual workflows for file processing, data transformation, and Google Sheets integration - no complex scripting required. It connects straight to Google Sheets and handles all the syntax headaches.
The visual interface makes spotting issues and tweaking automation logic much easier. You can also set up automatic triggers instead of running scripts manually.
You’re trying to run R code in Google Apps Script, which only speaks JavaScript. That’s why you’re getting the “name expected after dot operator” error. I did this exact same thing when moving analytics scripts from RStudio to Google Sheets. The syntax looks similar but they’re totally different languages. Your replaceText function doesn’t exist in JavaScript - you need string.replace() instead. That <- assignment operator on line 9 is a dead giveaway this was R code. Google Apps Script wants function declarations without that assignment stuff. Beyond fixing the syntax issues others mentioned, you need to completely rethink how you handle data. Google Sheets has built-in methods like getRange() and getValues() that work way better than trying to copy R’s data frame stuff. The SpreadsheetApp service handles most file operations you’ll need. Ditch the R port and start over with proper JavaScript syntax using Google’s APIs.