Errors while converting from numbers to character R - r

In R, I tried to see the summary of my data after converting them from numbers to characters and this message revealed continuously:
Error in nchar(x, type = "w"): invalid multibyte string, element 18

Sounds like a system locale issue. See this blog post for an example that may be similar to your case use.
In a nutshell, try running this before the rest of your code:
Sys.setlocale("LC_ALL", "English")

Related

Problem with analysis with special characters in getsymbols (PerformanceAnalytics)

I am trying to create a chart.correlation with the package PerformanceAnalytics. This works great like here:
if(!require("PerformanceAnalytics")) {install.packages("PerformanceAnalytics"); require("PerformanceAnalytics")}
library(PerformanceAnalytics)
#
getSymbols("AMZN",from="2016-01-01",to="2020-05-01")
getSymbols("TSLA",from="2016-01-01",to="2020-05-01")
data1<-cbind(diff(log(Cl(AMZN))),diff(log(Cl(TSLA))))
chart.Correlation(data1)
But as soon as there are special characters I get the following error:
Error: unexpected '^' in "data<-cbind(diff(log(Cl(UTDI.DE))),diff(log(Cl(^"
for the following code:
getSymbols("UTDI.DE",from="2016-01-01",to="2020-05-01")
getSymbols("^MDAXI",from="2016-01-01",to="2020-05-01")
data2<-cbind(diff(log(Cl(UTDI.DE))),diff(log(Cl(^MDAXI))))
chart.Correlation(data2)
Does anyone know how to use the special character here?

CharToDate(x) Error in R

I have a function named currency. It takes a parameter A which is a currency like "EUR/USD" . Then I do this: n<-getSymbols(A,src = "oanda",from = "2016-01-01",to = Sys.Date(),auto.assign = FALSE)
The paradox is that the program was running fine 2 days ago.
The error message is: Error in charToDate(x) : character string is not in a standard unambiguous format.
This is the traceback()
Thanks in advance!
I think that this a duplicate
quantmod::getFX function returns "character in a standard unambiguous format"
In any case, I followed the code of the getSymbols.oanda and it seems that oanda changed their API so instead of downloading a .csv you get a .xml file.
Speaking for me, I will go for a different source for the data until this is resolved by the quantmod guys.

read.csv replaces column-name characters like `?` with `.`, `-` with `...`

I'm using RStudio and my output on the Console gets truncated. I can't find how to stop the truncation (I tried searching ?options as well as googling around for longer than I'd like to admit).
EDIT: My apologies everyone! I originally had the long name as 'ThisIsAReallyReallyReallyReallyReallyLongName', but the issue only came up with the long name of 'Translation Service Info - Which translation service?'. I think I found the issue. The ... wasn't truncating, it was replacing the unknown characters like ? and - with . and ....
Code
# Load File
myfile <- read.csv(file="C:\\Users\\wliu\\Desktop\\myfile.csv",
sep=",", header=TRUE, stringsAsFactors=FALSE, skip=2)
# Get my column names
mycolnames <- colnames(myfile)
# When I request a shorter name, this returns the full name
mycolnames[1] # Assuming first col is a short name
[1] "ThisIsAShortName"
# However, when I request a longer name, this returns a truncated version
mycolnames[2] # Assuming second col is a really long name
[1] "ThisIsA...Long...Name"
I want to get back the non-truncated version of mycolnames[2] (e.g. "ThisIsAReallyReallyReallyReallyReallyLongName")
Setup
I'm on Windows 7 64bit, RStudio Version 0.98.1091, R version 3.0.1 (2013-05-16) -- "Good Sport" with Platform: x86_64-w64-mingw32/x64 (64-bit). I tried with 'Use Git Bash as shell for Git projects' on and off.
myfile.csv
ThisIsAShortName, Translation Service Info - Which translation service?
23143505, Yes
23143614, No
23143324, Yes
This is expected behavior by read.csv, not a truncation problem in R. When you have spaces and special characters in the column names of a file, read.csv replaces each of them with a . unless you specify check.names = FALSE
Here's a glimpse at make.names, which is how read.table produces the column names.
nm <- "Translation Service Info - Which translation service?"
make.names(nm)
# [1] "Translation.Service.Info...Which.translation.service."
And here's the relevant line from read.table
if (check.names)
col.names <- make.names(col.names, unique = TRUE)
In RStudio, use the menu:
Tools > Global Options > Code > Display
In the Console section, set Limit length of lines displayed in console to: to some number much larger than it currently is set to.
Click OK.
How about:
options(width=300)
Does that solve the issue?

Invalid specification in write.table()

I am encountering suddenly this odd error, which I have never come across before in write.table() command:
write.table(items,file="E:/CFA/items.dat",sep="\t",row.names=F,col.names=F)
Error in write.table(items, file = "E:/CFA/items.dat", :
invalid 'row.names' specification
When taking away the row.names argument, there is still the same error with col.names one. The data is a data frame which I have already worked with several times with no difficulties to create a .dat file. I am just puzzled.
Does anybody have a clue why it's happening now?
Thanks beforehand
Is it possible you have reassigned the F variable somewhere? Try doing it using FALSE instead of F.
write.table(items,file="E:/CFA/items.dat",sep="\t",row.names=FALSE,col.names=FALSE)
Try write.table(items,file="E://CFA//items.dat",sep="\t",row.names=F,col.names=F)
or rm(F,T) and then your command.

Kindly check the R command

I am doing following in Cooccur library in R.
> fb<-read.table("Fb6_peaks.bed")
> f1<-read.table("F16_peaks.bed")
everything is ok with the first two commands and I can also display the data:
> fb
> f1
But when I give the next command as given below
> explore_pairs(c("fb", "f1"))
I get an error message:
Error in sum(sapply(tf1_s, score_sample, tf2_hits = tf2_s, hit_list = hit_l)) :
invalid 'type' (list) of argument
Could anyone suggest something?
Despite promising to release a version to the Bioconductor depository in the article the authors published over a year ago, they have still not delivered. The gz file that is attached to the article is not of a form that my installation recognizes. Your really should be corresponding with the authors for this question.
The nature of the error message suggests that the function is expecting a different data class. You should be looking at the specification for the arguments in the help(explore_pairs) file. If it is expecting 2 matrices, then wrapping data.matrix around the arguments may solve the problem, but if it is expecting a class created by one of that packages functions then you need to take the necessary step to construct the right objects.
The help file for explore_pairs does exist (at least in the MAN directory) and says the first argument should be a character vector with further provisos:
\arguments{
\item{factornames}{an vector of character strings, each naming a GFF-like
data frame containing the binding profile of a DNA-binding factor.
There is also a load utility, load_GFF, which I assume is designed for creation of such files.
Try rename your data frame:
names(fb)=c("seq","start","end")
Check the example datasets. The column names are as above. I set the names and it worked.

Resources