Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I handle the error "Error: all(lengths == 1L | lengths == n) is not TRUE"?

I have been trying to solve this problem, but with no success. Imagine I have a google worksheet called "database". In this worksheet I have a sheet called "Sheet1". And in this sheet I have a table (that starts from A1) with column names "a1", "a2", "a3".

Now, I want to append a new row with values "12", "23", "34". For this I input this code:

library(googlesheets)

worksheet <- gs_title("database")
gs_add_row(ss=worksheet, ws="Sheet1", input = c("12","23","34"))

But when I do this, I get the following error:

Input is too long. Only first 0 elements will be used.
Error: all(lengths == 1L | lengths == n) is not TRUE

Thanks a lot

like image 677
Rodrigo Guinea Avatar asked Feb 16 '18 20:02

Rodrigo Guinea


1 Answers

gs_add_rows only can add rows once the header is available in the google sheet so you need to create the first row or the header information with gs_edit_cells() before you use add_rows.

This is explained in the googlesheets vignette.

Here is a screenshot of the appropriate code from the Vignette

like image 69
hank_044 Avatar answered Oct 30 '22 04:10

hank_044