Cannot use multi word variables in dplyr or am I missing something?Can dplyr summarise over several variables without listing each one?dplyr filter: Get rows with minimum of variable, but only the first if multiple minimadata.table vs dplyr: can one do something well the other can't or does poorly?dplyr - mutate: use dynamic variable namesCreate a ranking variable with dplyr?Change value of variable with dplyr“Adding missing grouping variables” message in dplyr in RHow to write loops “for” loops in R using dplyr syntaxgrouping in dplyr with missing columnsRepetitive filtering with multiple conditions without a loop

Why can't I share a one use code with anyone else?

How can I make dummy text (like lipsum) grey?

Refer a string as a field API name

Why is the marginal distribution/marginal probability described as "marginal"?

What would a Dragon have to exhale to cause rain?

I recently started my machine learning PhD and I have absolutely no idea what I'm doing

What color to choose as "danger" if the main color of my app is red

Why did nobody know who the Lord of this region was?

Why is Drogon so much better in battle than Rhaegal and Viserion?

When the match time is called, does the current turn end immediately?

Is it standard to have the first week's pay indefinitely withheld?

Why does string strummed with finger sound different from the one strummed with pick?

What are the effects of eating many berries from the Goodberry spell per day?

How to know the path of a particular software?

Do we see some Unsullied doing this in S08E05?

How do Ctrl+C and Ctrl+V work?

Why are there five extra turns in tournament Magic?

Deleting the same lines from a list

Iterate lines of string variable in bash

Would a "ring language" be possible?

How long do Aarakocra live?

Non-African Click Languages

Physically unpleasant work environment

What dog breeds survive the apocalypse for generations?



Cannot use multi word variables in dplyr or am I missing something?


Can dplyr summarise over several variables without listing each one?dplyr filter: Get rows with minimum of variable, but only the first if multiple minimadata.table vs dplyr: can one do something well the other can't or does poorly?dplyr - mutate: use dynamic variable namesCreate a ranking variable with dplyr?Change value of variable with dplyr“Adding missing grouping variables” message in dplyr in RHow to write loops “for” loops in R using dplyr syntaxgrouping in dplyr with missing columnsRepetitive filtering with multiple conditions without a loop






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








7















Why doesn't dplyr like this format of 'beta linalool' in my function as compared to beta.linalool?



It took me a few hours of troubleshooting to figure out what the problem was. Is there any way to use data where variables are labeled as more than one word or should I just move everything to the beta.linalool type format?



Everything I have learned has been from Programming with dplyr.



library(ggplot2)
library(readxl)
library(dplyr)
library(magrittr)

Data3<- read_excel("Desktop/Data3.xlsx")

Data3 %>% filter(Variety=="CS 420A"&`Red Blotch`=="-")%>% group_by(`Time Point`)%>%
summarise(m=mean(`beta linalool`),SD=sd(`beta linalool`))
# A tibble: 4 x 3
`Time Point` m SD
<chr> <dbl> <dbl>
1 End 0.00300 0.000117
2 Mid 0.00385 0.000353
3 Must 0.000254 0.00000633
4 Start 0.000785 0.000283


Now when I work it into a function:



cwine<-function(df,v,rb,c)
c<-enquo(c)
df %>% filter(Variety==v&`Red Blotch`==rb)%>%
group_by(`Time Point`) %>%
summarise_(m=mean(!!c),SD=sd(!!c)) %>%

cwine(Data3,"CS 420A","-",'beta linalool')
# A tibble: 4 x 3
`Time Point` m SD
<chr> <dbl> <dbl>
1 End NA NA
2 Mid NA NA
3 Must NA NA
4 Start NA NA
Warning messages:
1: In mean.default(~"beta linalool") :
argument is not numeric or logical: returning NA #this statement is repeated 4 more times
5: In var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm) :
NAs introduced by coercion #this statement is repeated 4 more times


The problem lies in that beta linalool is typed in as 'beta linalool'. I figured this out by trying this methodology on the iris dataset and seeing that Petal.Length is not 'Petal Width':



my_function<-function(ds,x,y,c)
c<-enquo(c)
ds %>%filter(Sepal.Length>x&Sepal.Width<y) %>%
group_by(Species) %>%
summarise(m=mean(!!c),SD=sd(!!c))

my_function2(iris,5,4,Petal.Length)
# A tibble: 3 x 3
Species m SD
<fct> <dbl> <dbl>
1 setosa 1.53 0.157
2 versicolor 4.32 0.423
3 virginica 5.57 0.536


In fact my function works fine on a different variable:



> cwine(Data2,"CS 420A","-",nerol)
# A tibble: 4 x 3
`Time Point` m SD
<chr> <dbl> <dbl>
1 End 0.000453 0.0000338
2 Mid 0.000659 0.0000660
3 Must 0.000560 0.0000234
4 Start 0.000927 0.0000224


Is dplyr just that sensitive or am I missing something?










share|improve this question



















  • 2





    Hadley and dplyr developers generally advocate for the naming convention: my_function_name and my_column_name to avoid such problems as occur when you have spaces in a column name.

    – NelsonGon
    May 5 at 5:40


















7















Why doesn't dplyr like this format of 'beta linalool' in my function as compared to beta.linalool?



It took me a few hours of troubleshooting to figure out what the problem was. Is there any way to use data where variables are labeled as more than one word or should I just move everything to the beta.linalool type format?



Everything I have learned has been from Programming with dplyr.



library(ggplot2)
library(readxl)
library(dplyr)
library(magrittr)

Data3<- read_excel("Desktop/Data3.xlsx")

Data3 %>% filter(Variety=="CS 420A"&`Red Blotch`=="-")%>% group_by(`Time Point`)%>%
summarise(m=mean(`beta linalool`),SD=sd(`beta linalool`))
# A tibble: 4 x 3
`Time Point` m SD
<chr> <dbl> <dbl>
1 End 0.00300 0.000117
2 Mid 0.00385 0.000353
3 Must 0.000254 0.00000633
4 Start 0.000785 0.000283


Now when I work it into a function:



cwine<-function(df,v,rb,c)
c<-enquo(c)
df %>% filter(Variety==v&`Red Blotch`==rb)%>%
group_by(`Time Point`) %>%
summarise_(m=mean(!!c),SD=sd(!!c)) %>%

cwine(Data3,"CS 420A","-",'beta linalool')
# A tibble: 4 x 3
`Time Point` m SD
<chr> <dbl> <dbl>
1 End NA NA
2 Mid NA NA
3 Must NA NA
4 Start NA NA
Warning messages:
1: In mean.default(~"beta linalool") :
argument is not numeric or logical: returning NA #this statement is repeated 4 more times
5: In var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm) :
NAs introduced by coercion #this statement is repeated 4 more times


The problem lies in that beta linalool is typed in as 'beta linalool'. I figured this out by trying this methodology on the iris dataset and seeing that Petal.Length is not 'Petal Width':



my_function<-function(ds,x,y,c)
c<-enquo(c)
ds %>%filter(Sepal.Length>x&Sepal.Width<y) %>%
group_by(Species) %>%
summarise(m=mean(!!c),SD=sd(!!c))

my_function2(iris,5,4,Petal.Length)
# A tibble: 3 x 3
Species m SD
<fct> <dbl> <dbl>
1 setosa 1.53 0.157
2 versicolor 4.32 0.423
3 virginica 5.57 0.536


In fact my function works fine on a different variable:



> cwine(Data2,"CS 420A","-",nerol)
# A tibble: 4 x 3
`Time Point` m SD
<chr> <dbl> <dbl>
1 End 0.000453 0.0000338
2 Mid 0.000659 0.0000660
3 Must 0.000560 0.0000234
4 Start 0.000927 0.0000224


Is dplyr just that sensitive or am I missing something?










share|improve this question



















  • 2





    Hadley and dplyr developers generally advocate for the naming convention: my_function_name and my_column_name to avoid such problems as occur when you have spaces in a column name.

    – NelsonGon
    May 5 at 5:40














7












7








7


1






Why doesn't dplyr like this format of 'beta linalool' in my function as compared to beta.linalool?



It took me a few hours of troubleshooting to figure out what the problem was. Is there any way to use data where variables are labeled as more than one word or should I just move everything to the beta.linalool type format?



Everything I have learned has been from Programming with dplyr.



library(ggplot2)
library(readxl)
library(dplyr)
library(magrittr)

Data3<- read_excel("Desktop/Data3.xlsx")

Data3 %>% filter(Variety=="CS 420A"&`Red Blotch`=="-")%>% group_by(`Time Point`)%>%
summarise(m=mean(`beta linalool`),SD=sd(`beta linalool`))
# A tibble: 4 x 3
`Time Point` m SD
<chr> <dbl> <dbl>
1 End 0.00300 0.000117
2 Mid 0.00385 0.000353
3 Must 0.000254 0.00000633
4 Start 0.000785 0.000283


Now when I work it into a function:



cwine<-function(df,v,rb,c)
c<-enquo(c)
df %>% filter(Variety==v&`Red Blotch`==rb)%>%
group_by(`Time Point`) %>%
summarise_(m=mean(!!c),SD=sd(!!c)) %>%

cwine(Data3,"CS 420A","-",'beta linalool')
# A tibble: 4 x 3
`Time Point` m SD
<chr> <dbl> <dbl>
1 End NA NA
2 Mid NA NA
3 Must NA NA
4 Start NA NA
Warning messages:
1: In mean.default(~"beta linalool") :
argument is not numeric or logical: returning NA #this statement is repeated 4 more times
5: In var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm) :
NAs introduced by coercion #this statement is repeated 4 more times


The problem lies in that beta linalool is typed in as 'beta linalool'. I figured this out by trying this methodology on the iris dataset and seeing that Petal.Length is not 'Petal Width':



my_function<-function(ds,x,y,c)
c<-enquo(c)
ds %>%filter(Sepal.Length>x&Sepal.Width<y) %>%
group_by(Species) %>%
summarise(m=mean(!!c),SD=sd(!!c))

my_function2(iris,5,4,Petal.Length)
# A tibble: 3 x 3
Species m SD
<fct> <dbl> <dbl>
1 setosa 1.53 0.157
2 versicolor 4.32 0.423
3 virginica 5.57 0.536


In fact my function works fine on a different variable:



> cwine(Data2,"CS 420A","-",nerol)
# A tibble: 4 x 3
`Time Point` m SD
<chr> <dbl> <dbl>
1 End 0.000453 0.0000338
2 Mid 0.000659 0.0000660
3 Must 0.000560 0.0000234
4 Start 0.000927 0.0000224


Is dplyr just that sensitive or am I missing something?










share|improve this question
















Why doesn't dplyr like this format of 'beta linalool' in my function as compared to beta.linalool?



It took me a few hours of troubleshooting to figure out what the problem was. Is there any way to use data where variables are labeled as more than one word or should I just move everything to the beta.linalool type format?



Everything I have learned has been from Programming with dplyr.



library(ggplot2)
library(readxl)
library(dplyr)
library(magrittr)

Data3<- read_excel("Desktop/Data3.xlsx")

Data3 %>% filter(Variety=="CS 420A"&`Red Blotch`=="-")%>% group_by(`Time Point`)%>%
summarise(m=mean(`beta linalool`),SD=sd(`beta linalool`))
# A tibble: 4 x 3
`Time Point` m SD
<chr> <dbl> <dbl>
1 End 0.00300 0.000117
2 Mid 0.00385 0.000353
3 Must 0.000254 0.00000633
4 Start 0.000785 0.000283


Now when I work it into a function:



cwine<-function(df,v,rb,c)
c<-enquo(c)
df %>% filter(Variety==v&`Red Blotch`==rb)%>%
group_by(`Time Point`) %>%
summarise_(m=mean(!!c),SD=sd(!!c)) %>%

cwine(Data3,"CS 420A","-",'beta linalool')
# A tibble: 4 x 3
`Time Point` m SD
<chr> <dbl> <dbl>
1 End NA NA
2 Mid NA NA
3 Must NA NA
4 Start NA NA
Warning messages:
1: In mean.default(~"beta linalool") :
argument is not numeric or logical: returning NA #this statement is repeated 4 more times
5: In var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm) :
NAs introduced by coercion #this statement is repeated 4 more times


The problem lies in that beta linalool is typed in as 'beta linalool'. I figured this out by trying this methodology on the iris dataset and seeing that Petal.Length is not 'Petal Width':



my_function<-function(ds,x,y,c)
c<-enquo(c)
ds %>%filter(Sepal.Length>x&Sepal.Width<y) %>%
group_by(Species) %>%
summarise(m=mean(!!c),SD=sd(!!c))

my_function2(iris,5,4,Petal.Length)
# A tibble: 3 x 3
Species m SD
<fct> <dbl> <dbl>
1 setosa 1.53 0.157
2 versicolor 4.32 0.423
3 virginica 5.57 0.536


In fact my function works fine on a different variable:



> cwine(Data2,"CS 420A","-",nerol)
# A tibble: 4 x 3
`Time Point` m SD
<chr> <dbl> <dbl>
1 End 0.000453 0.0000338
2 Mid 0.000659 0.0000660
3 Must 0.000560 0.0000234
4 Start 0.000927 0.0000224


Is dplyr just that sensitive or am I missing something?







r function dplyr






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 5 at 5:42









NelsonGon

5,0514934




5,0514934










asked May 5 at 5:11









andrewjcandrewjc

383




383







  • 2





    Hadley and dplyr developers generally advocate for the naming convention: my_function_name and my_column_name to avoid such problems as occur when you have spaces in a column name.

    – NelsonGon
    May 5 at 5:40













  • 2





    Hadley and dplyr developers generally advocate for the naming convention: my_function_name and my_column_name to avoid such problems as occur when you have spaces in a column name.

    – NelsonGon
    May 5 at 5:40








2




2





Hadley and dplyr developers generally advocate for the naming convention: my_function_name and my_column_name to avoid such problems as occur when you have spaces in a column name.

– NelsonGon
May 5 at 5:40






Hadley and dplyr developers generally advocate for the naming convention: my_function_name and my_column_name to avoid such problems as occur when you have spaces in a column name.

– NelsonGon
May 5 at 5:40













1 Answer
1






active

oldest

votes


















4














One option would be convert it to symbol and evaluate it



library(tidyverse)
cwine <- function(df,v,rb,c)

df %>%
filter(Variety==v & `Red Blotch` == rb)%>%
group_by(`Time Point`) %>%
summarise(m = mean(!!rlang::sym(c)),
SD = sd(!! rlang::sym(c)))


cwine(Data3,"CS 420A","-",'beta linalool')
# A tibble: 2 x 3
# `Time Point` m SD
# <int> <dbl> <dbl>
#1 2 -2.11 2.23
#2 4 0.0171 NA



Also, if we want to pass it by converting to quosure (enquo), it works, when we pass the variable name with backquotes (usually, unquoted version works, but here there is a space between words and to evaluate it as it is, backquote is needed)



cwine <- function(df,v,rb,c)
c1 <- enquo(c)
df %>%
filter(Variety==v & `Red Blotch` == rb)%>%
group_by(`Time Point`) %>%
summarise(m = mean(!! c1 ),
SD = sd(!! c1))


cwine(Data3,"CS 420A","-",`beta linalool`)
# A tibble: 2 x 3
# `Time Point` m SD
# <int> <dbl> <dbl>
#1 2 -2.11 2.23
#2 4 0.0171 NA


data



set.seed(24)
Data3 <- tibble(Variety = sample(c("CS 420A", "CS 410A"), 20, replace = TRUE),
`Red Blotch` = sample(c("-", "+"), 20, replace = TRUE),
`Time Point` = sample(1:4, 20, replace = TRUE),
`beta linalool` = rnorm(20))





share|improve this answer

























  • Unfortunately that resulted in "Error: Only strings can be converted to symbols Call rlang::last_error() to see a backtrace"

    – andrewjc
    May 5 at 5:19







  • 1





    @andrewjc I found some typos summarise_ in your code. Fixed it, can you try it now. I tried with a reproducible example and it is working fine for me

    – akrun
    May 5 at 5:34






  • 1





    I think summarise_ and the like were designed for SE. However, they seem to have lost favour(I think). They are infact deprecated.

    – NelsonGon
    May 5 at 5:43







  • 1





    @NelsonGon Yes, i misstyped as typo. the _ suffix was earlier used for NSE. Now, the rlang functions are mostly used for that purpose and convenient options with summarise_at/mutate_at/group_by_at takes a string column names and evaluates

    – akrun
    May 5 at 5:47






  • 2





    @akrun thank you for taking the time on this, what you recommended works well.

    – andrewjc
    May 5 at 6:07












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55989035%2fcannot-use-multi-word-variables-in-dplyr-or-am-i-missing-something%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














One option would be convert it to symbol and evaluate it



library(tidyverse)
cwine <- function(df,v,rb,c)

df %>%
filter(Variety==v & `Red Blotch` == rb)%>%
group_by(`Time Point`) %>%
summarise(m = mean(!!rlang::sym(c)),
SD = sd(!! rlang::sym(c)))


cwine(Data3,"CS 420A","-",'beta linalool')
# A tibble: 2 x 3
# `Time Point` m SD
# <int> <dbl> <dbl>
#1 2 -2.11 2.23
#2 4 0.0171 NA



Also, if we want to pass it by converting to quosure (enquo), it works, when we pass the variable name with backquotes (usually, unquoted version works, but here there is a space between words and to evaluate it as it is, backquote is needed)



cwine <- function(df,v,rb,c)
c1 <- enquo(c)
df %>%
filter(Variety==v & `Red Blotch` == rb)%>%
group_by(`Time Point`) %>%
summarise(m = mean(!! c1 ),
SD = sd(!! c1))


cwine(Data3,"CS 420A","-",`beta linalool`)
# A tibble: 2 x 3
# `Time Point` m SD
# <int> <dbl> <dbl>
#1 2 -2.11 2.23
#2 4 0.0171 NA


data



set.seed(24)
Data3 <- tibble(Variety = sample(c("CS 420A", "CS 410A"), 20, replace = TRUE),
`Red Blotch` = sample(c("-", "+"), 20, replace = TRUE),
`Time Point` = sample(1:4, 20, replace = TRUE),
`beta linalool` = rnorm(20))





share|improve this answer

























  • Unfortunately that resulted in "Error: Only strings can be converted to symbols Call rlang::last_error() to see a backtrace"

    – andrewjc
    May 5 at 5:19







  • 1





    @andrewjc I found some typos summarise_ in your code. Fixed it, can you try it now. I tried with a reproducible example and it is working fine for me

    – akrun
    May 5 at 5:34






  • 1





    I think summarise_ and the like were designed for SE. However, they seem to have lost favour(I think). They are infact deprecated.

    – NelsonGon
    May 5 at 5:43







  • 1





    @NelsonGon Yes, i misstyped as typo. the _ suffix was earlier used for NSE. Now, the rlang functions are mostly used for that purpose and convenient options with summarise_at/mutate_at/group_by_at takes a string column names and evaluates

    – akrun
    May 5 at 5:47






  • 2





    @akrun thank you for taking the time on this, what you recommended works well.

    – andrewjc
    May 5 at 6:07
















4














One option would be convert it to symbol and evaluate it



library(tidyverse)
cwine <- function(df,v,rb,c)

df %>%
filter(Variety==v & `Red Blotch` == rb)%>%
group_by(`Time Point`) %>%
summarise(m = mean(!!rlang::sym(c)),
SD = sd(!! rlang::sym(c)))


cwine(Data3,"CS 420A","-",'beta linalool')
# A tibble: 2 x 3
# `Time Point` m SD
# <int> <dbl> <dbl>
#1 2 -2.11 2.23
#2 4 0.0171 NA



Also, if we want to pass it by converting to quosure (enquo), it works, when we pass the variable name with backquotes (usually, unquoted version works, but here there is a space between words and to evaluate it as it is, backquote is needed)



cwine <- function(df,v,rb,c)
c1 <- enquo(c)
df %>%
filter(Variety==v & `Red Blotch` == rb)%>%
group_by(`Time Point`) %>%
summarise(m = mean(!! c1 ),
SD = sd(!! c1))


cwine(Data3,"CS 420A","-",`beta linalool`)
# A tibble: 2 x 3
# `Time Point` m SD
# <int> <dbl> <dbl>
#1 2 -2.11 2.23
#2 4 0.0171 NA


data



set.seed(24)
Data3 <- tibble(Variety = sample(c("CS 420A", "CS 410A"), 20, replace = TRUE),
`Red Blotch` = sample(c("-", "+"), 20, replace = TRUE),
`Time Point` = sample(1:4, 20, replace = TRUE),
`beta linalool` = rnorm(20))





share|improve this answer

























  • Unfortunately that resulted in "Error: Only strings can be converted to symbols Call rlang::last_error() to see a backtrace"

    – andrewjc
    May 5 at 5:19







  • 1





    @andrewjc I found some typos summarise_ in your code. Fixed it, can you try it now. I tried with a reproducible example and it is working fine for me

    – akrun
    May 5 at 5:34






  • 1





    I think summarise_ and the like were designed for SE. However, they seem to have lost favour(I think). They are infact deprecated.

    – NelsonGon
    May 5 at 5:43







  • 1





    @NelsonGon Yes, i misstyped as typo. the _ suffix was earlier used for NSE. Now, the rlang functions are mostly used for that purpose and convenient options with summarise_at/mutate_at/group_by_at takes a string column names and evaluates

    – akrun
    May 5 at 5:47






  • 2





    @akrun thank you for taking the time on this, what you recommended works well.

    – andrewjc
    May 5 at 6:07














4












4








4







One option would be convert it to symbol and evaluate it



library(tidyverse)
cwine <- function(df,v,rb,c)

df %>%
filter(Variety==v & `Red Blotch` == rb)%>%
group_by(`Time Point`) %>%
summarise(m = mean(!!rlang::sym(c)),
SD = sd(!! rlang::sym(c)))


cwine(Data3,"CS 420A","-",'beta linalool')
# A tibble: 2 x 3
# `Time Point` m SD
# <int> <dbl> <dbl>
#1 2 -2.11 2.23
#2 4 0.0171 NA



Also, if we want to pass it by converting to quosure (enquo), it works, when we pass the variable name with backquotes (usually, unquoted version works, but here there is a space between words and to evaluate it as it is, backquote is needed)



cwine <- function(df,v,rb,c)
c1 <- enquo(c)
df %>%
filter(Variety==v & `Red Blotch` == rb)%>%
group_by(`Time Point`) %>%
summarise(m = mean(!! c1 ),
SD = sd(!! c1))


cwine(Data3,"CS 420A","-",`beta linalool`)
# A tibble: 2 x 3
# `Time Point` m SD
# <int> <dbl> <dbl>
#1 2 -2.11 2.23
#2 4 0.0171 NA


data



set.seed(24)
Data3 <- tibble(Variety = sample(c("CS 420A", "CS 410A"), 20, replace = TRUE),
`Red Blotch` = sample(c("-", "+"), 20, replace = TRUE),
`Time Point` = sample(1:4, 20, replace = TRUE),
`beta linalool` = rnorm(20))





share|improve this answer















One option would be convert it to symbol and evaluate it



library(tidyverse)
cwine <- function(df,v,rb,c)

df %>%
filter(Variety==v & `Red Blotch` == rb)%>%
group_by(`Time Point`) %>%
summarise(m = mean(!!rlang::sym(c)),
SD = sd(!! rlang::sym(c)))


cwine(Data3,"CS 420A","-",'beta linalool')
# A tibble: 2 x 3
# `Time Point` m SD
# <int> <dbl> <dbl>
#1 2 -2.11 2.23
#2 4 0.0171 NA



Also, if we want to pass it by converting to quosure (enquo), it works, when we pass the variable name with backquotes (usually, unquoted version works, but here there is a space between words and to evaluate it as it is, backquote is needed)



cwine <- function(df,v,rb,c)
c1 <- enquo(c)
df %>%
filter(Variety==v & `Red Blotch` == rb)%>%
group_by(`Time Point`) %>%
summarise(m = mean(!! c1 ),
SD = sd(!! c1))


cwine(Data3,"CS 420A","-",`beta linalool`)
# A tibble: 2 x 3
# `Time Point` m SD
# <int> <dbl> <dbl>
#1 2 -2.11 2.23
#2 4 0.0171 NA


data



set.seed(24)
Data3 <- tibble(Variety = sample(c("CS 420A", "CS 410A"), 20, replace = TRUE),
`Red Blotch` = sample(c("-", "+"), 20, replace = TRUE),
`Time Point` = sample(1:4, 20, replace = TRUE),
`beta linalool` = rnorm(20))






share|improve this answer














share|improve this answer



share|improve this answer








edited May 5 at 5:37

























answered May 5 at 5:14









akrunakrun

432k13223311




432k13223311












  • Unfortunately that resulted in "Error: Only strings can be converted to symbols Call rlang::last_error() to see a backtrace"

    – andrewjc
    May 5 at 5:19







  • 1





    @andrewjc I found some typos summarise_ in your code. Fixed it, can you try it now. I tried with a reproducible example and it is working fine for me

    – akrun
    May 5 at 5:34






  • 1





    I think summarise_ and the like were designed for SE. However, they seem to have lost favour(I think). They are infact deprecated.

    – NelsonGon
    May 5 at 5:43







  • 1





    @NelsonGon Yes, i misstyped as typo. the _ suffix was earlier used for NSE. Now, the rlang functions are mostly used for that purpose and convenient options with summarise_at/mutate_at/group_by_at takes a string column names and evaluates

    – akrun
    May 5 at 5:47






  • 2





    @akrun thank you for taking the time on this, what you recommended works well.

    – andrewjc
    May 5 at 6:07


















  • Unfortunately that resulted in "Error: Only strings can be converted to symbols Call rlang::last_error() to see a backtrace"

    – andrewjc
    May 5 at 5:19







  • 1





    @andrewjc I found some typos summarise_ in your code. Fixed it, can you try it now. I tried with a reproducible example and it is working fine for me

    – akrun
    May 5 at 5:34






  • 1





    I think summarise_ and the like were designed for SE. However, they seem to have lost favour(I think). They are infact deprecated.

    – NelsonGon
    May 5 at 5:43







  • 1





    @NelsonGon Yes, i misstyped as typo. the _ suffix was earlier used for NSE. Now, the rlang functions are mostly used for that purpose and convenient options with summarise_at/mutate_at/group_by_at takes a string column names and evaluates

    – akrun
    May 5 at 5:47






  • 2





    @akrun thank you for taking the time on this, what you recommended works well.

    – andrewjc
    May 5 at 6:07

















Unfortunately that resulted in "Error: Only strings can be converted to symbols Call rlang::last_error() to see a backtrace"

– andrewjc
May 5 at 5:19






Unfortunately that resulted in "Error: Only strings can be converted to symbols Call rlang::last_error() to see a backtrace"

– andrewjc
May 5 at 5:19





1




1





@andrewjc I found some typos summarise_ in your code. Fixed it, can you try it now. I tried with a reproducible example and it is working fine for me

– akrun
May 5 at 5:34





@andrewjc I found some typos summarise_ in your code. Fixed it, can you try it now. I tried with a reproducible example and it is working fine for me

– akrun
May 5 at 5:34




1




1





I think summarise_ and the like were designed for SE. However, they seem to have lost favour(I think). They are infact deprecated.

– NelsonGon
May 5 at 5:43






I think summarise_ and the like were designed for SE. However, they seem to have lost favour(I think). They are infact deprecated.

– NelsonGon
May 5 at 5:43





1




1





@NelsonGon Yes, i misstyped as typo. the _ suffix was earlier used for NSE. Now, the rlang functions are mostly used for that purpose and convenient options with summarise_at/mutate_at/group_by_at takes a string column names and evaluates

– akrun
May 5 at 5:47





@NelsonGon Yes, i misstyped as typo. the _ suffix was earlier used for NSE. Now, the rlang functions are mostly used for that purpose and convenient options with summarise_at/mutate_at/group_by_at takes a string column names and evaluates

– akrun
May 5 at 5:47




2




2





@akrun thank you for taking the time on this, what you recommended works well.

– andrewjc
May 5 at 6:07






@akrun thank you for taking the time on this, what you recommended works well.

– andrewjc
May 5 at 6:07




















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55989035%2fcannot-use-multi-word-variables-in-dplyr-or-am-i-missing-something%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Club Baloncesto Breogán Índice Historia | Pavillón | Nome | O Breogán na cultura popular | Xogadores | Adestradores | Presidentes | Palmarés | Historial | Líderes | Notas | Véxase tamén | Menú de navegacióncbbreogan.galCadroGuía oficial da ACB 2009-10, páxina 201Guía oficial ACB 1992, páxina 183. Editorial DB.É de 6.500 espectadores sentados axeitándose á última normativa"Estudiantes Junior, entre as mellores canteiras"o orixinalHemeroteca El Mundo Deportivo, 16 setembro de 1970, páxina 12Historia do BreogánAlfredo Pérez, o último canoneiroHistoria C.B. BreogánHemeroteca de El Mundo DeportivoJimmy Wright, norteamericano do Breogán deixará Lugo por ameazas de morteResultados de Breogán en 1986-87Resultados de Breogán en 1990-91Ficha de Velimir Perasović en acb.comResultados de Breogán en 1994-95Breogán arrasa al Barça. "El Mundo Deportivo", 27 de setembro de 1999, páxina 58CB Breogán - FC BarcelonaA FEB invita a participar nunha nova Liga EuropeaCharlie Bell na prensa estatalMáximos anotadores 2005Tempada 2005-06 : Tódolos Xogadores da Xornada""Non quero pensar nunha man negra, mais pregúntome que está a pasar""o orixinalRaúl López, orgulloso dos xogadores, presume da boa saúde económica do BreogánJulio González confirma que cesa como presidente del BreogánHomenaxe a Lisardo GómezA tempada do rexurdimento celesteEntrevista a Lisardo GómezEl COB dinamita el Pazo para forzar el quinto (69-73)Cafés Candelas, patrocinador del CB Breogán"Suso Lázare, novo presidente do Breogán"o orixinalCafés Candelas Breogán firma el mayor triunfo de la historiaEl Breogán realizará 17 homenajes por su cincuenta aniversario"O Breogán honra ao seu fundador e primeiro presidente"o orixinalMiguel Giao recibiu a homenaxe do PazoHomenaxe aos primeiros gladiadores celestesO home que nos amosa como ver o Breo co corazónTita Franco será homenaxeada polos #50anosdeBreoJulio Vila recibirá unha homenaxe in memoriam polos #50anosdeBreo"O Breogán homenaxeará aos seus aboados máis veteráns"Pechada ovación a «Capi» Sanmartín e Ricardo «Corazón de González»Homenaxe por décadas de informaciónPaco García volve ao Pazo con motivo do 50 aniversario"Resultados y clasificaciones""O Cafés Candelas Breogán, campión da Copa Princesa""O Cafés Candelas Breogán, equipo ACB"C.B. Breogán"Proxecto social"o orixinal"Centros asociados"o orixinalFicha en imdb.comMario Camus trata la recuperación del amor en 'La vieja música', su última película"Páxina web oficial""Club Baloncesto Breogán""C. B. Breogán S.A.D."eehttp://www.fegaba.com

Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020