我編寫了一個R包,其中包含使用xts
對象的S4類。這是我的理解,我需要包括行setOldClass(「xts」)導致自定義R包中的問題
setOldClass("xts")
stock.returns <- setClass(
Class = "stock.returns",
slots = c(xts_returns = "xts", timeframe = "timeframe", currency = "character"),
prototype = prototype(xts_returns = xts::xts(, order.by = c(lubridate::today())), timeframe = timeframe(), currency = "Local")
)
在我的類定義腳本的頂部。當我使用我的包創建我的對象時,會發生問題。它的工作原理,但我偶爾得到這樣的警告反覆幾次:
Found more than one class "xts" in cache; using the first, from namespace 'quantmod'
我怎麼能強迫我的班,而不是使用默認爲quantmod
包正確xts
包?如果不這樣做,我該如何至少停止警告?
我注意到Hadley Wickham和另一個人在同一主題上的對話:http://r.789695.n4.nabble.com/setOldClass-quot-xts-quot-td4714332.html。它無處可去。
編輯:我的空間文件
# Generated by roxygen2: do not edit by hand
export("%>%")
export(EOMonth)
export(EOWeek)
export(VaR.cree)
export(date_to_sql_string)
export(df_to_xts)
export(ewma)
export(factor_model_maker)
export(flatten_xts)
export(get_USD_fx)
export(get_benchmark_index)
export(get_benchmark_xts_returns)
export(get_bond_index)
export(get_currency_index)
export(get_end_date)
export(get_financial_history)
export(get_financial_history_and_make_it_monthly)
export(get_frequency)
export(get_fund_performance)
export(get_fx_USD_history)
export(get_fx_cross)
export(get_index_snapshot)
export(get_metrics_history)
export(get_portfolio)
export(get_price_history)
export(get_shock_results)
export(get_shock_results.yield_version)
export(get_spc_xts_raw_total_returns)
export(get_spc_xts_returns)
export(get_start_date)
export(get_table_from_sql_CISMPRDSVR)
export(get_test_date)
export(get_ticker_xts_return_index)
export(get_ticker_xts_t_data_fs_eps)
export(get_watchlist)
export(get_yield_index)
export(market_capture_ratio)
export(previous_business_date_if_weekend)
export(price_plot)
export(rel_plot)
export(return_over_horizon)
export(rolling_correlation)
export(run_sql_in_CISMPRDSVR)
export(scenario_analysis)
export(show_regression)
export(single_experiment_summary)
export(stock.returns)
export(timeframe)
export(update_fund_performance_from_spreadsheet)
export(write.zoo)
export(xts_add_average_series)
export(xts_price_from_returns)
export(xts_returns)
exportClasses(timeframe)
而我的描述文件:
Package: cree
Title: CI Risk Engine, Eh?
Version: 0.0.0.9000
[email protected]: person("Mr", "lebelinoz", email = "[email protected]", role = c("aut", "cre"))
Description: All the in-house risk tools built in R.
Depends: R (>= 3.3.1)
License: Proprietary. Do not distribute outside My Company Limited.
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.0.1
Imports:
tidyverse,
lubridate,
quantmod,
xts,
zoo,
RODBC,
PerformanceAnalytics
Collate:
'Functions.R'
'Sql_Wrapper.R'
'StockPlot.R'
'VaR.cree.R'
'ewma.R'
'timeframe.R'
'stock.returns.R'
'factor_model_maker.R'
'get_benchmark_index.R'
'get_bond_index.R'
'get_currency_index.R'
'get_financial_history.R'
'get_fx_.R'
'get_metrics_history.R'
'get_portfolio.R'
'get_price_history.R'
'get_shock_results.R'
'get_shock_results.yield_version.R'
'get_yield_index.R'
'market_capture_ratio.R'
'return_over_horizon.R'
'scenario_analysis.R'
'show_regression.R'
'show_regression_between_xts.R'
'single_experiment_summary.R'
'update_fund_performance_from_spreadsheet.R'
你有沒有嘗試使用'::'運算符?例如:'xts ::'以避免衝突? – ar7
@ ar7是的我有,但它會導致編譯錯誤。我已經添加了示例類,以幫助澄清我的問題。 – lebelinoz
您的NAMESPACE和DESCRIPTION文件也是相關的。您的軟件包源代碼是否公開? –