Error in View : invalid caption argument

Asked

Viewed 241 times

1

I was working on the following script:

library(tidyverse) 
library(dplyr) 
library(readxl) 

cirurgia <- read_excel("C:/Users/Agnes/Desktop/Coisas com R/R/2_MIOMECTOMIA_HISTERECTOMIA-MAR_SET-2017.xlsx", 
                       sheet = "Plan1", 
                       col_types = c("text", "text", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric", "numeric")) 
View(cirurgia) 
pretas <- cirurgia %>% 
 select(estado, PROCEDIMENTO, PRETA, PARDA, TOTAL) %>% 
 filter(PROCEDIMENTO == "HISTERECTOMIA TOTAL") %>% 
 View(pretas)

Error in View : invalid caption argument

What does that mean?

  • The error is here, select(cirurgia, etc, cannot have the dataframe on select. Unless cirurgia be it the name of a column.

  • I edited the question, now the mistake is this :( .

  • 1

    I would remove the %>% just before View(black). Or simply switch from View(black) to View.

  • What @Ailtonandradedeoliveira is saying is that pretas does not yet exist, is the value of the instruction but only after it has completed. Enough View with or without () empty. And then, in the next line, without the pipe %>%, can be View(pretas). Ah, if you carry the package tidyverse the dplyr is also loaded.

  • Can you please, edit the question with the departure of dput(cirurgia) or, if the base is too large, dput(head(cirurgia, 20))?

1 answer

2

What’s happening here is independent of your database.

Remember that the operator %>% causes the object to its left to be used as argument of the function to its right.

Therefore, the following two lines are equivalent:

mtcars %>% View()
View(mtcars)

When you do:

x <- mtcars %>% View(x)

You’re doing something equivalent to:

x <- View(mtcars, x)

However, the variable x It doesn’t exist yet, so that’s equivalent to:

x <- View(mtcars, NULL)

It turns out that the second argument of the function View is a title for the table and that title cannot be NULL, therefore the mistake:

Error in View : invalid caption argument

Browser other questions tagged

You are not signed in. Login or sign up in order to post.