我有一个双循环,如下所示 的问题是R(2.15.2)使用越来越多的内存,我不明白为什么.
虽然我知道这必须在内循环中发生,因为rbind()我在那里做,我不明白为什么R在外循环的新循环开始时实际上重复使用对象('xmlCatcher')时继续抓取内存:
# !!!BEWARE this example creates a lot of files (n=1000)!!!!
require(XML)
chunk <- function(x, chunksize){
# source: http://stackoverflow.com/a/3321659/1144966
x2 <- seq_along(x)
split(x, ceiling(x2/chunksize))
}
chunky <- chunk(paste("test",1:1000,".xml",sep=""),100)
for(i in 1:1000){
writeLines(c(paste('<?xml version="1.0"?>\n <note>\n <to>Tove</to>\n <nr>',i,'</nr>\n <from>Jani</from>\n <heading>Reminder</heading>\n ',sep=""), paste(rep('<body>Do not forget me this weekend!</body>\n',sample(1:10, 1)),sep="" ) , ' </note>')
,paste("test",i,".xml",sep=""))
}
for(k in 1:length(chunky)){
gc()
print(chunky[[k]])
xmlCatcher <- NULL
for(i in 1:length(chunky[[k]])){
filename <- chunky[[k]][i]
xml <- xmlTreeParse(filename)
xml <- xmlRoot(xml)
result <- sapply(getNodeSet(xml,"//body"), …Run Code Online (Sandbox Code Playgroud) R CMD check在我的包上运行时,我收到以下警告消息:
Found the following assignments to the global environment:
File ‘SciencesPo/R/describe.R’:
assign(as.character(substitute(data)), dataset, pos = 1)
Run Code Online (Sandbox Code Playgroud)
我试图通过使用, 和添加此处提到的环境来使其静音,但收到了相同的消息。envir = .SciencesPoEnvenvir = .GlobalEnv
有谁知道我该如何解决它?
对于我的基本问题,我很抱歉.我想增加标签的字体大小.我试过了cex.label.但它不起作用.
pie(c(3632,20,491,991,120))
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个从向量的每个元素中减去 2 的函数,每当我将向量作为参数传递给该函数时,它都会输出错误:
sub(x) 中的错误:缺少参数“x”,没有默认值。
所以我有一个名为 x1 的向量,我的函数调用如下所示: sub(x1)
任何帮助将不胜感激。
sub <- function(x)
{
for(i in 1:length(x))
{
x[i] = x[i]-2
}
return(x)
}
Run Code Online (Sandbox Code Playgroud)