2

I am trying to use Pipe Operators in my R code but I keep getting an error saying the "mutate" function could not be found. I have already installed/loaded dplyr and tidyverse which apparently include magrittr, so I'm not sure what to do.

Any help would be very appreciated, thanks.

df_reg <- df %>% 
  group_by(hhid) %>% 
  mutate(
    across(
      .col = c(all_of(cons_list), all_of(percap_cons_list)),
      .fns = function(x) x / 1000,
      .names = "{col}"
    ),
Error in mutate(., across(.col = c(all_of(cons_list), all_of(percap_cons_list)),  : 
  could not find function "mutate"

SessionInfo() Output

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] stargazer_5.2.2 lfe_2.8-6       Matrix_1.2-17   haven_2.4.1     sf_0.9-8       

loaded via a namespace (and not attached):
 [1] zoo_1.8-8          tidyselect_1.1.0   xfun_0.16          purrr_0.3.4       
 [5] lattice_0.20-38    colorspace_1.4-1   vctrs_0.3.6        generics_0.0.2    
 [9] yaml_2.2.1         rlang_0.4.10       e1071_1.7-6        pillar_1.4.6      
[13] glue_1.4.2         DBI_1.0.0          dbplyr_2.1.1       modelr_0.1.8      
[17] lifecycle_1.0.0    munsell_0.5.0      gtable_0.3.0       knitr_1.29        
[21] forcats_0.5.1      class_7.3-15       broom_0.7.6        Rcpp_1.0.5        
[25] KernSmooth_2.23-15 xtable_1.8-4       readr_1.4.0        scales_1.1.1      
[29] backports_1.1.4    classInt_0.4-3     jsonlite_1.7.2     ggplot2_3.3.4     
[33] hms_1.0.0          dplyr_1.0.4        grid_3.6.1         cli_2.5.0         
[37] tools_3.6.1        sandwich_3.0-0     magrittr_2.0.1     proxy_0.4-25      
[41] tibble_3.0.4       Formula_1.2-4      pacman_0.5.1       crayon_1.4.1      
[45] tidyr_1.1.2        pkgconfig_2.0.2    ellipsis_0.3.1     lubridate_1.7.10  
[49] assertthat_0.2.1   httr_1.4.2         rstudioapi_0.13    R6_2.4.0          
[53] units_0.7-1        compiler_3.6.1  

library(dplyr) output

> library(dplyr)
Warning: package ‘dplyr’ was built under R version 3.6.3

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
Matt
  • 97
  • 10
  • 3
    `library(dplyr)`? *Installing* it does not make it immediately available, you must instruct R to start using it. – r2evans Jun 20 '21 at 02:23
  • 2
    Please show the output of `sessionInfo()`. But more than likely you just didn't load the library as already pointed out. You must do that each R session you want to use `dplyr` commands. – MrFlick Jun 20 '21 at 02:33
  • Oh I meant to say 'loaded" . @MrFlick I've added the output from sessionInfo(). – Matt Jun 20 '21 at 02:38
  • 2
    `dplyr` is not listed in "other attached packages" of your session info so it is not available to be used directly. What is the exact output you get when you run `library(dplyr)`? you cannot call functions from packages that are not attached to the search path. – MrFlick Jun 20 '21 at 02:39
  • Ah I'm not familiar with "other attached packages" but thanks for pointing that out. And Ill add the output to the post above. The output says its attaching the package dplyr. I didn't realize it hadn't been properly loaded. @MrFlick – Matt Jun 20 '21 at 02:43
  • 1
    After you run `library(dplyr)` is it listed in "other attached packages" in `sessionInfo()`? If it is, then you should be able to run the code again and at the very least get a different error message. – MrFlick Jun 20 '21 at 03:57

0 Answers0