Adapted from Google Earth Engine Documentation.

This doc describes coding practices that are intended to maximize the chance of success for complex or expensive Earth Engine computations.

Avoid mixing client functions and objects with server functions and objects

Earth Engine server objects are objects with constructors that start with ee (e.g. ee$Image, ee$Reducer) and any methods on such objects are server functions. Any object not constructed in this manner is a client object. Client objects may come from the R Earth Engine client (e.g. Map) or the R language (e.g. date, data.frame, c(), list()).

To avoid unintended behavior, do not mix client and server functions in your script as discussed here. See this page for in-depth explanation of client vs. server in Earth Engine. The following example illustrates the dangers of mixing client and server functionality:

  Error — This code doesn’t work!

# Won't work.
for (i in seq_len(table$size())) {

Can you spot the error? Note that table$size() is a server method on a server object and can not be used with client-side functionality such as the seq_len function.

A situation in which you may want to use for-loops is with to display results with Map, since the Map object and methods are client-side.