0

I know that certain functions are possible to use only when library is loaded.

For example to use raster function from raster package I need to:

library(raster)
raster("msi1986.img") #see the summary of img.file in working directory

Or...

I can indicate the library without loading it (by using name of library::function)

raster::raster("msi1986.img")

Both ways produce the same results.

My problem is that I can not use name of library::function for dplyr package.

Part of my script looks like this:

# rescaling table via "dplyr"
library(dplyr)
my.df.R = betw_frame %>%
    group_by(id) %>% # group by id
    mutate(value = value - min(value), value = value - lag(value)) %>% # group min to 0, difference lag 1
    na.omit %>% # remove NA caused by lag 1 differencing
    arrange(id, value) %>% # order by value within each id
    mutate(time = 1:length(value)) %>% # Make a time variable from 1 to 5 based on current order
    select(-year) # remove year column to match final OP output

I tried this but it is not working.

my.df.R = betw_frame dplyr::%>%
    group_by(id) dplyr::%>% # group by id
    mutate(value = value - min(value), value = value - lag(value)) dplyr::%>% # group min to 0, difference lag 1
    na.omit dplyr::%>% # remove NA caused by lag 1 differencing
    arrange(id, value) dplyr::%>% # order by value within each id
    mutate(time = 1:length(value)) dplyr::%>% # Make a time variable from 1 to 5 based on current order
    select(-year) # remove year column to match final OP output

Is there a way how to indicate library other than dplyr::%>% ?

Reproducible example can be found in my previous question and answer by @aosmith here.

Community
  • 1
  • 1
Ladislav Naďo
  • 822
  • 12
  • 27
  • 1
    You would also need to make use of `dplyr::` for all the other functions from dplyr like `group_by`, `mutate`, `arrange` etc. – talat Nov 13 '14 at 16:12
  • What exactly does "not working" mean? You didn't provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – MrFlick Nov 13 '14 at 16:23
  • 1
    At the very least you'd need to wrap the function in quotes. This works: `dplyr::'%>%'(1:10, head)`. – jbaums Nov 13 '14 at 16:36

0 Answers0