Problems with 'select' function, unknown column rlang error appears

Hey,

I was trying to make a data table 'dt' with function 'select' and after running the whole line there appeared error that one of the columns from the data set is unknown. Show 'rlang error' but have no clue how to deal with it. Checked the excel file as well, no mistakes in it.

PLEASE HELP ME ASAP!!!

dt <- select(macro, "Laikas", ... , "Paslaugos|paslaugų įmonių rodikliai - paslaugų įmonių pardavimo pajamos (be PVM), tūkst. EUR, I55 Apgyvendinimo veikla ekonominės veiklos rūšis")

From what I can see (which isn't much — reading from screenshots is hard), it looks like you've tried to select a column that doesn't exist in your data frame.

Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.

install.packages("reprex")

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don'ts are also useful.

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "fruits_stringdist.md")

For pointers specific to the community site, check out the reprex FAQ.

Tried to turn it into reprex for the very first time, hope I got you right. Here is what I got as a result from the clipboard:

# Nustatome darbine direktorija.
setwd("C:/Users/el ruchenzo/Desktop/STATISTIKA")

# Instaliuojame reikiamus paketus:
#install.packages("readxl")
#install.packages("forecast")
#install.packages("ggplot2")
#install.packages("dplyr")
#install.packages("reshape")
#install.packages("Ecdat")
# Paketai:
library("readxl")
library("ggplot2")
library("dplyr")
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library("forecast")
library("reshape")
#> 
#> Attaching package: 'reshape'
#> The following object is masked from 'package:dplyr':
#> 
#>     rename
library("Ecdat")
#> Loading required package: Ecfun
#> 
#> Attaching package: 'Ecfun'
#> The following object is masked from 'package:forecast':
#> 
#>     BoxCox
#> The following object is masked from 'package:base':
#> 
#>     sign
#> 
#> Attaching package: 'Ecdat'
#> The following object is masked from 'package:datasets':
#> 
#>     Orange


# Ikeliame 2 paruostas duomenu rinkmenas - "macro" ir "apklausa" (toliau - "duom")
duom <- read.csv2("PGS2011.csv",header = T,sep = ",")
macro <- read_excel("macro.xlsx", skip = 1)

##### 1. #####

# Atliekame sezonine dekompozicija rinkmenos "macro" duomenims.
# is duomenu atimti sezonine dali reikes/arba dalinti, priklauso nuo metodo
head(macro)
#> # A tibble: 6 x 9
#>   Laikas              `BVP to meto ka~ `Bendroji pride~ `Galutinio vart~
#>   <dttm>                         <dbl>            <dbl>            <dbl>
#> 1 2007-01-01 00:00:00            6031.            1009.            5011.
#> 2 2007-04-01 00:00:00            7176.            1153.            5877.
#> 3 2007-07-01 00:00:00            7834.            1212.            5915.
#> 4 2007-10-01 00:00:00            7999.            1241.            6725.
#> 5 2008-01-01 00:00:00            7167.            1220.            6154.
#> 6 2008-04-01 00:00:00            8483.            1384.            7035.
#> # ... with 5 more variables: `Nedarbo lygis - 15-64m., mieste ir kaime,
#> #   vyru ir moteru, proc.` <dbl>, `Užimti gyventojai - 15-64m., mieste,
#> #   moteru, tukst.` <dbl>, `Profesija (gydytojai) - EUR (menesinis),
#> #   bruto` <dbl>, `Akcizai, tukst. EUR, visi moketojai` <dbl>,
#> #   `Paslaugos|paslaugu imoniu rodikliai - paslaugu imoniu pardavimo
#> #   pajamos (be PVM), tukst. EUR, I55 Apgyvendinimo veikla ekonomines
#> #   veiklos rušis` <dbl>
tail(macro)
#> # A tibble: 6 x 9
#>   Laikas              `BVP to meto ka~ `Bendroji pride~ `Galutinio vart~
#>   <dttm>                         <dbl>            <dbl>            <dbl>
#> 1 2017-01-01 00:00:00            9358.            1708.            7706.
#> 2 2017-04-01 00:00:00           10470.            1713.            8492.
#> 3 2017-07-01 00:00:00           11328             1885.            8386.
#> 4 2017-10-01 00:00:00           11035.            1944.            8895.
#> 5 2018-01-01 00:00:00            9930.            1827.            8202.
#> 6 2018-04-01 00:00:00           11204.            1806.            9063.
#> # ... with 5 more variables: `Nedarbo lygis - 15-64m., mieste ir kaime,
#> #   vyru ir moteru, proc.` <dbl>, `Užimti gyventojai - 15-64m., mieste,
#> #   moteru, tukst.` <dbl>, `Profesija (gydytojai) - EUR (menesinis),
#> #   bruto` <dbl>, `Akcizai, tukst. EUR, visi moketojai` <dbl>,
#> #   `Paslaugos|paslaugu imoniu rodikliai - paslaugu imoniu pardavimo
#> #   pajamos (be PVM), tukst. EUR, I55 Apgyvendinimo veikla ekonomines
#> #   veiklos rušis` <dbl>
dt <- select_at(macro, "Laikas","BVP to meto kainomis, mln EUR, nepasalinus sezono ir darbo dienu skaiciaus itakos\r\n","Bendroji pridetine verte, mln EUR, C Apdirbamoji pramone ekonomines veiklos rusis, nepasalinus sezono ir darbo dienu skaiciaus itakos","Galutinio vartojimo islaidos, mln EUR, nepasalinus sezono ir darbo dienu skaiciaus itakos","Nedarbo lygis - 15-64m., mieste ir kaime, vyru ir moteru, proc.","Uzimti gyventojai - 15-64m., mieste, moteru, tukst.","Profesija (gydytojai) - EUR (menesinis), bruto","Akcizai, tukst. EUR, visi moketojai","Paslaugos|paslaugu imoniu rodikliai - paslaugu imoniu pardavimo pajamos (be PVM), tukst. EUR, I55 Apgyvendinimo veikla ekonomines veiklos rusis")
#> Error in `BVP to meto kainomis, mln EUR, nepasalinus sezono ir darbo dienu skaiciaus itakos\r\n`(., : could not find function "BVP to meto kainomis, mln EUR, nepasalinus sezono ir darbo dienu skaiciaus itakos\r\n"
dt <- select_all(macro)
#sitas veikia, anas ne
head(dt)
#> # A tibble: 6 x 9
#>   Laikas              `BVP to meto ka~ `Bendroji pride~ `Galutinio vart~
#>   <dttm>                         <dbl>            <dbl>            <dbl>
#> 1 2007-01-01 00:00:00            6031.            1009.            5011.
#> 2 2007-04-01 00:00:00            7176.            1153.            5877.
#> 3 2007-07-01 00:00:00            7834.            1212.            5915.
#> 4 2007-10-01 00:00:00            7999.            1241.            6725.
#> 5 2008-01-01 00:00:00            7167.            1220.            6154.
#> 6 2008-04-01 00:00:00            8483.            1384.            7035.
#> # ... with 5 more variables: `Nedarbo lygis - 15-64m., mieste ir kaime,
#> #   vyru ir moteru, proc.` <dbl>, `Užimti gyventojai - 15-64m., mieste,
#> #   moteru, tukst.` <dbl>, `Profesija (gydytojai) - EUR (menesinis),
#> #   bruto` <dbl>, `Akcizai, tukst. EUR, visi moketojai` <dbl>,
#> #   `Paslaugos|paslaugu imoniu rodikliai - paslaugu imoniu pardavimo
#> #   pajamos (be PVM), tukst. EUR, I55 Apgyvendinimo veikla ekonomines
#> #   veiklos rušis` <dbl>

dplyr::select(
  macro,
  "Laikas",
  "BVP to meto kainomis, mln EUR, nepasalinus sezono ir darbo dienu skaiciaus itakos\r\n",
  "Bendroji pridetine verte, mln EUR, C Apdirbamoji pramone ekonomines veiklos rusis, nepasalinus sezono ir darbo dienu skaiciaus itakos",
  "Galutinio vartojimo islaidos, mln EUR, nepasalinus sezono ir darbo dienu skaiciaus itakos",
  "Nedarbo lygis - 15-64m., mieste ir kaime, vyru ir moteru, proc.",
  "Uzimti gyventojai - 15-64m., mieste, moteru, tukst.",
  "Profesija (gydytojai) - EUR (menesinis), bruto",
  "Akcizai, tukst. EUR, visi moketojai",
  "Paslaugos|paslaugu imoniu rodikliai - paslaugu imoniu pardavimo pajamos (be PVM), tukst. EUR, I55 Apgyvendinimo veikla ekonomines veiklos rusis"
)
#> Error: Unknown column `BVP to meto kainomis, mln EUR, nepasalinus sezono ir darbo dienu skaiciaus itakos
#> `


BVPts <- ts(dt$`BVP to meto kainomis, mln EUR, nepasalinus sezono ir darbo dienu skaiciaus itakos`, frequency = 4, start = c(2007/1/1))
#> Warning: Unknown or uninitialised column: 'BVP to meto kainomis, mln EUR,
#> nepasalinus sezono ir darbo dienu skaiciaus itakos'.
#> Error in ts(dt$`BVP to meto kainomis, mln EUR, nepasalinus sezono ir darbo dienu skaiciaus itakos`, : 'ts' object must have one or more observations

Also tried to delete that column with an error from the function, but then appears same error in another column.

@Andrea is this a valid reprex? setwd issue is the same as mine

EDIT: to be precise, kndrtt correctly used the reprex package. However, using the reprex package helps creating a reproducible example, but unfortunately it's not enough. This is a difficult point to convey, and something which I myself struggled with when, some years ago, I started using Stack Overflow, when the reprex package didn't actually exist, but people were (and of course still are) expecting you to write a post containing a MRE (Minimum Reproducible Example). A very good discussion explaining why using reprex helps, but is not enough, to build a reproducible example:

As in joelt92 case, the issue is nearly never just setwd itself: the point is that setwd is usually the premise to a sequence of instructions which no one else, apart from the OP, can perform. For example, if I were to run kndrtt code on my machine, these lines would fail, even if I had a folder STATISTIKA somewhere in my file system:

duom <- read.csv2("PGS2011.csv",header = T,sep = ",") 
macro <- read_excel("macro.xlsx", skip = 1)

because I don't have files PGS2011.csv and macro.xlsx on my machine. This is explained very well in the reprex dos and don'ts link that Mara already shared above -- the very first suggestion is to use the smallest, simplest, most built-in data possible. And the reason is exactly that, otherwise, we won't be able to run your code.

3 Likes

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