I messed up with something but I don't know where to look. My guess is that something happened when I updated some packages in emacs but I don't know which one exactly. Any help would be appreciated Even running a basic command like the following:
\begin{document}
<<test>>=
1+1
#
\end{document}
yield the following error
label: test
Quitting from lines 39-40 (/tmp/tmp.rnw)
Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 3, 0
In addition: Warning messages:
1: In is.na(res[, 1]) :
is.na() applied to non-(list or vector) of type 'NULL'
2: In is.na(res) : is.na() applied to non-(list or vector) of type 'NULL'
and here is the stack trace:
+ Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 3, 0
----------------------------------
22: stop(gettextf("arguments imply differing number of rows: %s",
paste(unique(nrows), collapse = ", ")), domain = NA)
21: data.frame(..., check.names = FALSE)
20: cbind(deparse.level, ...)
19: cbind(z[, c("line1", "col1", "line2", "col2", "text")], merge_cmd(z,
markup))
18: (if (fallback) hi_naive else hilight_one)(code, format, markup,
escape_fun)
17: highr::hilight(x, format, prompt = options$prompt, markup = opts$markup)
16: hilight_source(x, "latex", options)
15: (knit_hooks$get("source"))(src, options)
14: wrap.source(X[[1L]], ...)
13: FUN(X[[1L]], ...)
12: lapply(x, wrap, options)
11: wrap.list(res, options)
10: wrap(res, options)
9: unlist(wrap(res, options))
8: block_exec(params)
7: call_block(x)
6: process_group.block(group)
5: process_group(group)
4: withCallingHandlers(if (tangle) process_tangle(group) else process_group(group),
error = function(e) {
setwd(wd)
cat(res, sep = "\n", file = output %n% "")
message("Quitting from lines ", paste(current_lines(i),
collapse = "-"), " (", knit_concord$get("infile"),
") ")
})
3: process_file(text, output)
2: knit(input, output = output, envir = envir, quiet = quiet, encoding = encoding)
1: knit2pdf("tmp.rnw")
Update
## R version 3.1.2 (2014-10-31)
## Platform: x86_64-redhat-linux-gnu (64-bit)
## locale:
## [1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C
## [3] LC_TIME=en_US.utf8 LC_COLLATE=en_US.utf8
## [5] LC_MONETARY=en_US.utf8 LC_MESSAGES=en_US.utf8
## [7] LC_PAPER=en_US.utf8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
## other attached packages:
## [1] knitr_1.10.5
## loaded via a namespace (and not attached):
## [1] compiler_3.1.2 evaluate_0.7 formatR_1.2 highr_0.5 stringr_1.0.0
## [6] tcltk_3.1.2 tools_3.1.2
Ran into the same problem today. For me this was fixed by upgrading the knitr packge from version 1.10.5 to version 1.11., the evaluate package from version 0.7 to version 0.7.2, the formatR package from version 0.9 to version 1.2, and the highr package from version 0.2.1 to version 0.5.
I upgraded these in order and it only worked after upgrading highr, so I suspect that this is the culprit.
Sigh, looks like it's probably time to update.packages().
Related
I have a .csv file which is UTF-8 encoded when I saved it. The script is Devanagari of the data in this file. I am able to see the words in csv file in excel
में
लिए
किया
गया
हैं
नहीं
सिंह
पुलिस
दिया
करने
कहा
रहे
बाद
करें
साथ
रहा
But when I open that in R, the words do not get encoded correctly. the output for print() is like this:
word
सारे_खतरों_को
जानते_हà¥\u0081à¤\u008f_à¤à¥€
विवेक_ने
टीवी
How can I resolve this? I have tried Sys.setlocale() and read.delim(wordlist.csv, encoding = "UTF-8") but neither worked.
Too long for comment (sorry, I'm a greenhorn in R):
print( sessionInfo())
library(stringi)
library(magrittr)
x <- read.delim("D:\\bat\\SO\\64497248_devangari.csv", encoding = "UTF-8")
print('=== print(x)')
print(x)
for (line in x){
y <- line %>%
stri_replace_all_regex("<U\\+([[:alnum:]]+)>", "\\\\u$1") %>%
stri_unescape_unicode() %>%
stri_enc_toutf8()
}
print('=== print(y)')
print(y)
print('=== for (i in y) {print(i)}')
for (i in y) {print(i)}
print('=== print(z)')
z <- x['word'] %>%
stri_replace_all_regex("<U\\+([[:alnum:]]+)>", "\\\\u$1") %>%
stri_unescape_unicode() %>%
stri_enc_toutf8()
print(z)
Output (in Rgui.exe console):
> source ( 'D:\\bat\\SO\\64497248.r' )
R version 4.0.1 (2020-06-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)
Matrix products: default
locale:
[1] LC_COLLATE=Czech_Czechia.1250 LC_CTYPE=Czech_Czechia.1250 LC_MONETARY=Czech_Czechia.1250
[4] LC_NUMERIC=C LC_TIME=Czech_Czechia.1250
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.0.1
[1] "=== print(x)"
word
1 <U+092E><U+0947><U+0902>
2 <U+0932><U+093F><U+090F>
3 <U+0915><U+093F><U+092F><U+093E>
4 <U+0917><U+092F><U+093E>
5 <U+0939><U+0948><U+0902>
6 <U+0928><U+0939><U+0940><U+0902>
7 <U+0938><U+093F><U+0902><U+0939>
8 <U+092A><U+0941><U+0932><U+093F><U+0938>
9 <U+0926><U+093F><U+092F><U+093E>
10 <U+0915><U+0930><U+0928><U+0947>
11 <U+0915><U+0939><U+093E>
12 <U+0930><U+0939><U+0947>
13 <U+092C><U+093E><U+0926>
14 <U+0915><U+0930><U+0947><U+0902>
15 <U+0938><U+093E><U+0925>
16 <U+0930><U+0939><U+093E>
[1] "=== print(y)"
[1] "में" "लिए" "किया" "गया" "हैं" "नहीं" "सिंह" "पुलिस" "दिया" "करने" "कहा" "रहे" "बाद" "करें" "साथ" "रहा"
[1] "=== for (i in y) {print(i)}"
[1] "में"
[1] "लिए"
[1] "किया"
[1] "गया"
[1] "हैं"
[1] "नहीं"
[1] "सिंह"
[1] "पुलिस"
[1] "दिया"
[1] "करने"
[1] "कहा"
[1] "रहे"
[1] "बाद"
[1] "करें"
[1] "साथ"
[1] "रहा"
[1] "=== print(z)"
[1] "c(\"में\", \"लिए\", \"किया\", \"गया\", \"हैं\", \"नहीं\", \"सिंह\", \"पुलिस\", \"दिया\", \"करने\", \"कहा\", \"रहे\", \"बाद\", \"करें\", \"साथ\", \"रहा\"\n)"
Warning messages:
1: package ‘magrittr’ was built under R version 4.0.2
2: In stri_replace_all_regex(., "<U\\+([[:alnum:]]+)>", "\\\\u$1") :
argument is not an atomic vector; coercing
>
My code runs fine but fails in a package
I boiled it down to
wtf<-function(r)
{
require(raster)
stopifnot(class(r) == "RasterLayer")
return(as.matrix(r))
}
When sourced, everything works fine. When the function is part of a package, it fails. It nicely runs in debug mode though, step by step.
library(mypackage)
r <- raster(ncol=6, nrow=6)
r[] <- runif(ncell(r),0,1)
extent(r) <- matrix(c(0, 0, 6, 6), nrow=2)
wtf(r)
# Error in as.vector(data) :
# no method for coercing this S4 class to a vector
# Traceback
# 5 as.vector(data)
# 4 array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x),
# NULL) else NULL)
# 3 as.matrix.default(r)
# 2 as.matrix(r) at terrain.R#7
# 1 wtf(s)
I'm a bit puzzeled as to why this happens and to how proceed.
The build went fine, the check went clean, so what is going on?
What would be the next question to ask and explore in order to solve the problem?
R version 3.1.1 (2014-07-10)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] raster_2.3-0 spdep_0.5-77 Matrix_1.1-4 minerva_1.4.1 gdata_2.13.3 rgdal_0.9-1 sp_1.0-15
loaded via a namespace (and not attached):
[1] boot_1.3-11 coda_0.16-1 deldir_0.1-5 grid_3.1.1 gtools_3.4.1 lattice_0.20-29 LearnBayes_2.15 MASS_7.3-33 nlme_3.1-118 parallel_3.1.1 splines_3.1.1 tools_3.1.1
The traceback shows that the default as.matrix is used, rather than the raster variant. I believe this problem goes away if you add this line to your Namespace file:
import(raster)
Or when you are explicit about which as.matrix you want:
wtf <- function(r) {
stopifnot(inherits(r, "RasterLayer"))
raster::as.matrix(r)
}
Rather than 'manually' testing for class membership, you might consider a more formal (S4) approach:
if (!isGeneric("wtf")) {
setGeneric("wtf", function(x, ...)
standardGeneric("wtf"))
}
setMethod("wtf", signature(x='RasterLayer'),
function(x, ...) {
raster::as.matrix(x)
}
)
I am applying similar add.distribution rule as in the luxor-demo while my strategy has only a long position.
The whole strategy works, but when applying a parameterset I get following error:
TakeProfitLONG 47 0.047
TakeProfitLONG 47 0.047 result of evaluating expression:
simpleError in param.combo[[param.label]]: subscript out of bounds
got results for task 47 numValues: 47, numResults: 47, stopped: FALSE
returning status FALSE evaluation # 48: $param.combo
I am trying to run a distribution on a simple takeProfit rule (get same result from stopLoss or trailingStop):
.use.takeProfit = TRUE
.takeprofit <- 2.0/100 # actual
.TakeProfit = seq(0.1, 4.8, length.out=48)/100 # parameter set for optimization
## take-profit
add.rule(strategy.st, name = 'ruleSignal',
arguments=list(sigcol='signal.gt.zero' , sigval=TRUE,
replace=FALSE,
orderside='long',
ordertype='limit',
tmult=TRUE,
threshold=quote(.takeprofit),
TxnFees=.txnfees,
orderqty='all',
orderset='ocolong'
),
type='chain',
parent='EnterLONG',
label='TakeProfitLONG',
enabled=.use.takeProfit
)
I am adding the distribution as follows:
add.distribution(strategy.st,
paramset.label = 'TakeProfit',
component.type = 'chain',
component.label = 'TakeProfitLONG',
variable = list(threshold = .TakeProfit),
label = 'TakeProfitLONG'
)
and apply the set:
results <- apply.paramset(strategy.st, paramset.label='TakeProfit', portfolio.st=portfolio.st, account.st=account.st, nsamples=.nsamples, verbose=TRUE)
From my limited debugging it seems that the parameterset is a simple vector whereas in the apply.paramset following function fails:
results <- fe %dopar% { ... }
Here I am too new to R as i am only 4 weeks looking into this, but possibly a call to:
install.param.combo <- function(strategy, param.combo, paramset.label)
might cause the error?
Have to apologize as I am to new, but did anyone encounter this or could help how to apply a distribution to only one item in a long only strategy?
Many thanks in advance!
EDIT 1: SessionInfo()
R version 3.1.2 (2014-10-31)
Platform: i486-pc-linux-gnu (32-bit)
locale:
[1] C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] lattice_0.20-29 iterators_1.0.7 downloader_0.3
[4] quantstrat_0.9.1665 foreach_1.4.2 blotter_0.9.1644
[7] PerformanceAnalytics_1.4.3574 FinancialInstrument_1.2.0 quantmod_0.4-3
[11] TTR_0.22-0.1 xts_0.9-7 zoo_1.7-12
loaded via a namespace (and not attached):
[1] codetools_0.2-9 compiler_3.1.2 digest_0.6.7 grid_3.1.2 tools_3.1.2
This is the same bug as # 5776. It was fixed for "signal" component types, but not for "chain". It should now be fixed as of revision 1669 on R-Forge.
library(Biobase)
library(GEOquery)
gds4577 <- getGEO(filename='c:/test/GDS4577_full.soft.gz')
eset <- GDS2eSet(gds4577, do.log2=TRUE)
> eset <- GDS2eSet(gds4577, do.log2=TRUE)
File stored at:
C:\DOCUME~1\sanya\LOCALS~1\Temp\RtmpQtuak0/GPL1261.annot.gzC:\DOCUME~1\sanya\LOCALS~1\Temp\RtmpQtuak0/GPL1261.annot.gz
Error in gzfile(fname, open = "rt") : invalid 'description' argument
In addition: Warning messages:
1: In if (GSEMatrix & geotype == "GSE") { :
the condition has length > 1 and only the first element will be used
2: In if (geotype == "GDS") { :
the condition has length > 1 and only the first element will be used
3: In if (geotype == "GSE" & amount == "full") { :
the condition has length > 1 and only the first element will be used
4: In if (geotype == "GSE" & amount != "full" & amount != "table") { :
the condition has length > 1 and only the first element will be used
5: In if (geotype == "GPL") { :
the condition has length > 1 and only the first element will be used
6: In if (!file.exists(destfile)) { :
the condition has length > 1 and only the first element will be used
7: In download.file(myurl, destfile, mode = mode, quiet = TRUE, method = getOption("download.file.method.GEOquery")) :
only first element of 'url' argument used
8: In download.file(myurl, destfile, mode = mode, quiet = TRUE, method = getOption("download.file.method.GEOquery")) :
only first element of 'destfile' argument used
> eset
Error: object 'eset' not found
what is the matter with my computer?
> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: i386-w64-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=Chinese_People's Republic of China.936 LC_CTYPE=Chinese_People's Republic of China.936
[3] LC_MONETARY=Chinese_People's Republic of China.936 LC_NUMERIC=C
[5] LC_TIME=Chinese_People's Republic of China.936
attached base packages:
[1] parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] GEOquery_2.28.0 BiocInstaller_1.12.0 affy_1.40.0 Biobase_2.22.0 BiocGenerics_0.8.0
loaded via a namespace (and not attached):
[1] affyio_1.30.0 preprocessCore_1.24.0 RCurl_1.95-4.1 tools_3.0.2 XML_3.98-1.1 zlibbioc_1.8.0
GEOquery currently does not handle the case of the "full_soft" file, a file that is a combination of the GDS expression and the GPL information associated with the GDS. I've put parsing the full_soft format on my TODO list. For the time being, avoiding the "full_soft" file format is what I would recommend, also. Doing so is not a problem since GEOquery will reconstruct the "full_soft" file contents when importing a GDS using the standard GEOquery workflow.
I want to make a f-test to a plm-model and test for
model <- plm(y ~ a + b)
if
# a = b
and
# a = 0 and b = 0
I tried linearHypothesis like this
linearHypothesis(ur.model, c("a", "b")) to test for a = 0 and b = 0
but got the error
Error in constants(lhs, cnames_symb) :
The hypothesis "sgp1" is not well formed: contains bad coefficient/variable names.
Calls: linearHypothesis ... makeHypothesis -> rbind -> Recall -> makeHypothesis -> constants
In addition: Warning message:
In constants(lhs, cnames_symb) : NAs introduced by coercion
Execution halted
My example above is with code that is a little simplified if the problem is easy. If the problems is in the details is the actual code here.
model3 <- formula(balance.agr ~ sgp1 + sgp2 + cp + eu + election + gdpchange.imf + ue.ameco)
ur.model<-plm(model3, data=panel.l.fullsample, index=c("country","year"), model="within", effect="twoways")
linearHypothesis(ur.model, c("sgp1", "sgp2"), vcov.=vcovHC(plmmodel1, method="arellano", type = "HC1", clustering="group"))
I can't reproduce your error with one of the inbuilt data sets, even after quite a bit of fiddling.
Does this work for you?
require(plm)
require(car)
data(Grunfeld)
form <- formula(inv ~ value + capital)
re <- plm(form, data = Grunfeld, model = "within", effect = "twoways")
linearHypothesis(re, c("value", "capital"),
vcov. = vcovHC(re, method="arellano", type = "HC1"))
Note also, that you seem to have an error in the more complex code you showed. You are using linearHypothesis() on the object ur.model, yet call vcovHC() on object plmmodel1. Not sure if that is the problem or not, but check that in case.
Is it possible to provide the data? Finally, edit your Question to include output from sessionInfo(). Mine is (from quite a busy R instance):
> sessionInfo()
R version 2.11.1 Patched (2010-08-25 r52803)
Platform: x86_64-unknown-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_GB.utf8 LC_NUMERIC=C
[3] LC_TIME=en_GB.utf8 LC_COLLATE=en_GB.utf8
[5] LC_MONETARY=C LC_MESSAGES=en_GB.utf8
[7] LC_PAPER=en_GB.utf8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.utf8 LC_IDENTIFICATION=C
attached base packages:
[1] splines grid stats graphics grDevices utils datasets
[8] methods base
other attached packages:
[1] car_2.0-2 nnet_7.3-1 plm_1.2-6 Formula_1.0-0
[5] kinship_1.1.0-23 lattice_0.19-11 nlme_3.1-96 survival_2.35-8
[9] mgcv_1.6-2 chron_2.3-37 MASS_7.3-7 vegan_1.17-4
[13] lmtest_0.9-27 sandwich_2.2-6 zoo_1.6-4 moments_0.11
[17] ggplot2_0.8.8 proto_0.3-8 reshape_0.8.3 plyr_1.2.1
loaded via a namespace (and not attached):
[1] Matrix_0.999375-44 tools_2.11.1
Could it be because you are "mixing" models? You have a variance specification that starts out:
, ...vcov.=vcovHC(plmmodel1,
... and yet you are working with ur.model.