如何通过RDCOMClient在Excel中更改图表标题?

如何通过RDCOMClient包在Excel中更改图表的标题?

我可以创build一个图表并获得其标题如下:

# Load package and helper functions - see http://www.omegahat.org/RDCOMClient require(RDCOMClient) source("http://www.omegahat.org/RDCOMClient/examples/excelUtils.R") # Create Excel application xls <- COMCreate("Excel.Application") # Make Excel workbook visible to user xls[["Visible"]] <- TRUE # Add a worksheet to the workbook wb = xls[["Workbooks"]]$Add(1) # Add data.frame to worksheet df <- data.frame(x=c("a", "b", "c"), Income = 4:6) exportDataFrame(df, at = wb$ActiveSheet()$Range("A1")) # Add Chart chart.display.range <- wb$ActiveSheet()$Range("D2:H12") wb$ActiveSheet()$Range("A1:B4")$Select() wb$ActiveSheet()$Shapes()$AddChart(Top = chart.display.range$Top(), Left = chart.display.range$Left(), Height = chart.display.range$Height(), Width = chart.display.range$Width())$Select() # chart title wb$ActiveChart()$ChartTitle()[["Text"]] #[1] "Income" 

但是当我尝试改变名字

 # Change chart title?? wb$ActiveChart()$ChartTitle()[["Text"]] <- "Tony's Chart" 

我得到一个错误:

 Error in wb$ActiveChart()$ChartTitle()[["Text"]] <- "Tony's Chart" : invalid (NULL) left side of assignment 

我似乎经常遇到这种types的问题,我不能改变一个属性值,并想弄清楚如何解决这个问题(我知道我可以改变data.frame列的名称,但我希望更好解决scheme,因为我可能错过了非常明显的东西)。

提前致谢。

 > sessionInfo() R version 3.0.0 (2013-04-03) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C [5] LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] excel.link_0.5.4 zoo_1.7-10 RDCOMClient_0.93-0.1 data.table_1.8.8 ggplot2_0.9.3.1 plyr_1.8 reshape2_1.2.2 countrycode_0.14 loaded via a namespace (and not attached): [1] colorspace_1.2-2 dichromat_2.0-0 digest_0.6.3 grid_3.0.0 gtable_0.1.2 labeling_0.1 lattice_0.20-15 MASS_7.3-26 munsell_0.4 [10] proto_0.3-10 RColorBrewer_1.0-5 scales_0.2.3 stringr_0.6.2 tools_3.0.0 

通过在R中input随机的东西来找出它:

 x = wb$ActiveChart()$ChartTitle() x[["Text"]] = "Tony's Chart" 

我想知道为什么我不能像我的问题那样直接做到这一点?