R: 2 functions with the same name in 2 different packages

前端 未结 4 1333
無奈伤痛
無奈伤痛 2020-11-30 00:59

I need to load to R packages : tseries and chron

Both have a function named is.weekend

I always have in my environment the function from the second package I

4条回答
  •  长情又很酷
    2020-11-30 01:35

    i had 2 packages who had same function name ts() The 2 pacckages who had the same were :

    1. forecast
    2. List item

    I inspected what was going on by typing

    ?ts
    
    
    Help on topic 'ts' was found in the following packages:
    
    Time-Series Objects
    (in package stats in library C:/Program Files/R/R-3.6.2/library)
    Format time stamps
    (in package bReeze in library C:/Users/mycomputer/Documents/R/win-library/3.6)
    

    Solution : Then to use the function ts that comes with package forecast i used : because the help showed me that forcast was calling stats

    Time-Series Objects (in package stats

    stats::ts
    

    because is saw from help that forecasts use a package called stats ;)

    forecast::ts
    
    Time-Series Objects
    (in package stats
    

    was giving me error, because forecast package was using a sub package ;

    so final usage looks like this :

    library(bReeze)
    library(forecast)
    
    # Subset data
    my_time_series <- stats::ts(c(df_sub$y), start=2018, frequency = 12)
    
    # Plot
    theme_set(theme_classic())
    ggseasonplot(my_time_series) + labs(title="My graph title")
    

提交回复
热议问题