How to solve "can't subset columns that don't exist"?

I use this R script to track our Twitter followers, but it didn't work this time and says x Column screen_name doesn't exist. Could you please help with the test? Thank you very much! Here is the script:

rm(list=ls())

########## Twitter_Account#######

#install.packages('rtweet')

library(rtweet)

#install.packages('dplyr')

library(dplyr)

#install.packages("tidyverse")

library(tidyverse)

#install.packages("writexl")

library(writexl)

twitter_data <- lookup_users(c("FAOMoscow","FAOBurundi","FAOauTogo","FAOJordan","FAOCaribbean","FAORDCongo", "FAObotswana","FAOOman","FAOPakistan","FAOinUAE","FAOCameroun",

                           "FAOCaboVerde","FAOSyria","FAOAfghanistan","FAOAlgerie","FAOEgypt", 

                           "FAONamibia","FAOMali","FAOIndigenous","FAODG","FAOBurkinaFaso", 

                           "FAONigeria","FAOTchad","FAOSenegal","FAOBolivia","FAOHaiti","FAOChile", 

                           "FAOWestAfrica","FAOJapan","FAONiger","FAOBrussels","FAOBrasilCoop","FAOMozambique", 

                           "FAOBrasil","FAOTanzania","FAOEthiopia","FAOVietNam","FaoAngola","FAOPacific", 

                           "FAOAfriqueCent","FAOEcuador","FAOSierraLeone","FAOZambia","FAO_SANA","faoturkiye", 

                           "FAOEspana","FAOWHOCodex","FAO_Colombia","FAOPhilippines","FAONicaragua","FAOLandWater", 

                           "FAOGhana","FAORwanda","FAOPERU","FAOLiberia","FAOIran","FAOAsiaPacific","FAOEritrea", 

                           "FAOParaguay","UN_CFS","AMISoutlook","FAOUganda","FAOMesoamerica","faosfsafrica", 

                           "FAOBangladesh","FAOCuba","FAOArgentina","FAOMalawi","FAOSaudiArabia","FAOHonduras", 

                           "FaoUruguay","FAOElSalvador","FAOMadagascar","FAOFFKP","FAOSIDS","FAOinNENA_EN", 

                           "FAOInvest","FAOIndonesia","FAOSouthSudan","FAOSWALIM","faodominicana","FAOpesca", 

                           "FAOstatistics","FAOForestry","FAOAfeeding","FAO_AgriFam","FAOawelfare","FAONewYork", 

                           "FAOEastAfrica","FAOGuatemala","FAONorthAmerica","FAOAfrica","FAOwbf","FAOKenya", 

                           "FAOfish","UN_FAO_GFCM","FAOcomdev","FAOCotedIvoire","FAOinNENA","FAOJobs","FAORussian", 

                           "FAOsomalia","FAO_Venezuela","FAOAmericas","FAOclimate","ippcnews","FAOFSNForum", 

                           "FAOLivestock","FAOCostaRica","FAOemergencies","FAOSDGs","planttreaty", 

                           "ALCsinhambre","FAOMexico","FAO4Members","FAOeagriculture","FAOUkraine","FAOKazakhstan", 

                           "FAOmesoamerica","FAOinPNG","FAOLebanon","FAOAIMS","FAOGuineaEcua","faodjibouti","FAOSudan", 

                           "FAOGuinee","FAOMongolia","FAOIndia","FAOGeneva","FAOYemen","FAOScienceChief","FAOIraq","faosouthafrica", 

                           "FAOSriLanka","FAOGuineaBissau","FAOInnovation","FAOSouthKorea","FAOADG_NENA","FAOAfricaADG","FAOAzerbaijan", 

                           "FaoBenin","FAOBhutan","FAOCapacitacion","FAOCongo","FAOEswatini","FAOGambia","faolocust","FAOMaroc","FSCluster", 

                           "GACSA_news","UN_YUNGA","FAOSocioEcon","FAOMauritania","FaoCf","FAOinNepal","FAOCentrafrique","FAOCambodia","FAOMoldova", 

                           "FAO","FAOnews","FAOKnowledge","FAOenEspanol","FAOarabic","FAOenfrancais")) 

total_followers<-select(twitter_data,screen_name,followers_count)

write_xlsx(total_followers,"twitter.xlsx")

the gold standard approach is to know for sure what columns exist.
use names() for this
like

names(twitter_data)

are screen_name and followers_count exact matches within there ? R

Which version of rtweet are you using? With version 1.0 or higher you don't have those columns. See this blog post about how to do it: rOpenSci | Upgrading rtweet

Note that you can't save it to a excel file because there are nested characters in the twitter_data object

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.