最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Out of range values when reading a MATLAB file with R.matlab - Stack Overflow

programmeradmin5浏览0评论

I have dowloaded a MATLAB file with species names and their ecological group from /

In step 5 on this page the file library.mat can be downloaded (zipped). I then use the function readMat() from the R.matlab library to read this file:

library(R.matlab)    
ambi<-readMat("library.mat")

I get this 7 warnings:

Warning messages:

1: In convertUTF8(ary) :
out-of-range values treated as 0 in coercion to raw  
2: In convertUTF8(ary) :
out-of-range values treated as 0 in coercion to raw  
3: In convertUTF8(ary) :
out-of-range values treated as 0 in coercion to raw  
4: In convertUTF8(ary) :
out-of-range values treated as 0 in coercion to raw  
5: In convertUTF8(ary) :
out-of-range values treated as 0 in coercion to raw  
6: In convertUTF8(ary) :
out-of-range values treated as 0 in coercion to raw  
7: In convertUTF8(ary) :
out-of-range values treated as 0 in coercion to raw

I don't know what this means but I suspect it has something to do with encodings. I would be very thankful if someone can tell me what the reason is and how I can solve this problem. I don't have MATLAB. I am using R version 4.4.3 on Swedish Windows 11.

I have dowloaded a MATLAB file with species names and their ecological group from https://ambi.azti.es/download/

In step 5 on this page the file library.mat can be downloaded (zipped). I then use the function readMat() from the R.matlab library to read this file:

library(R.matlab)    
ambi<-readMat("library.mat")

I get this 7 warnings:

Warning messages:

1: In convertUTF8(ary) :
out-of-range values treated as 0 in coercion to raw  
2: In convertUTF8(ary) :
out-of-range values treated as 0 in coercion to raw  
3: In convertUTF8(ary) :
out-of-range values treated as 0 in coercion to raw  
4: In convertUTF8(ary) :
out-of-range values treated as 0 in coercion to raw  
5: In convertUTF8(ary) :
out-of-range values treated as 0 in coercion to raw  
6: In convertUTF8(ary) :
out-of-range values treated as 0 in coercion to raw  
7: In convertUTF8(ary) :
out-of-range values treated as 0 in coercion to raw

I don't know what this means but I suspect it has something to do with encodings. I would be very thankful if someone can tell me what the reason is and how I can solve this problem. I don't have MATLAB. I am using R version 4.4.3 on Swedish Windows 11.

Share Improve this question edited Mar 25 at 17:56 M-- 29.5k10 gold badges69 silver badges106 bronze badges Recognized by R Language Collective asked Mar 25 at 15:47 Mats_BMats_B 1451 silver badge8 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

I looks like R.matlab is doing you a favour by omitting those characters. While I am not an SME, an internet search suggests those characters are often omitted from the affected species names so perhaps they are errors? At least there are only seven to deal with if you have to manually edit them.

To examine the issue, you can use the rmatio package, as it will retain the non-UTF characters.

library(rmatio)
library(stringi)

# Unzip .mat previously downloaded from
# https://azti.sharepoint/sites/Proyectos/AMBI/Documentos%20compartidos/Forms/AllItems.aspx?id=%2Fsites%2FProyectos%2FAMBI%2FDocumentos%20compartidos%2FLibrary%2D2024%2Ezip&parent=%2Fsites%2FProyectos%2FAMBI%2FDocumentos%20compartidos&p=true&ga=1
# Edit file path where necessary
unzip("data/AMBI/Library-2024.zip",
      files = "library.mat",
      exdir = "data/AMBI/")

ambi <- read.mat("data/AMBI/library.mat")

# Convert to df
df <- data.frame(name = unlist(ambi$specieslist$name),
                 group = unlist(ambi$specieslist$group),
                 reassign = unlist(ambi$specieslist$reassign))

# Return rows containing non-UTF
x <- df[which(stri_enc_mark(df$name) == "native"),]

x$name
# [1] "Congetia chesneyi\xfd"     "Erythrops go\xfdsi"        "Erythrops go\xfdsii"      
# [4] "Gymnonereis\xfdcrosslandi" "Hippolyte cura\xfdaoensis" "Neorhynchoplax\xfdsp."    
# [7] "Valencinia\xfdsp."

# Convert non-UTF chars
iconv(x$name, from = "macroman", to = "UTF-8")
# [1] "Congetia chesneyi˝"     "Erythrops go˝si"        "Erythrops go˝sii"      
# [4] "Gymnonereis˝crosslandi" "Hippolyte cura˝aoensis" "Neorhynchoplax˝sp."    
# [7] "Valencinia˝sp."

The closest encoding I could find was "macroman" but it is still not correct. Again, not an SME, but it appears that in some cases, those non-UTF characters are supposed to be either a "ë", or not there at all. If there is uncertainty, the only thing I can suggest is to contact the data maintainers to find out the correct encoding, or whether these are indeed errors. At least then you can rule out whether it's something to do with R.

发布评论

评论列表(0)

  1. 暂无评论