Problems with R script to prepare species lists for Collect

  • Asked
  • Active
  • Viewed 4331 times
0

Dear OF Team,

I would like to import a rather long species list (csv >700 MB) to Collect, using the provided R-scripts (https://drive.google.com/open?id=1FKe3dlFRgw1IrUmUtF6q02j4qDr9gkki). As reference, I am working with the PDF Species coding approach for Open Foris Collect and Calc. However, I can't get the script to work properly as the following step keeps resulting in an error:

split scientific names into genus and species

sp_dt[, c( "genus", "species", "tspecies", "subspecies" ) := tstrsplit(scientific_name, " ", fixed=FALSE)] Error in [.data.table(sp_dt, , :=(c("genus", "species", "tspecies", : Supplied 4 columns to be assigned 2 items. Please see NEWS for v1.12.2.

Even though I am considering splitting the csv into separate species lists according to the taxonomical order, I'd still need the script to work.

Can anybody point me in the right direction to find the source of this error?

Thank you very much in advance,

Alex

1

Accepted answer

Dear Alex, thanks for sharing your data. I fixed two issues in the R script:

1) Microsoft applications may add weird characters into the column names, and this was the case in your CSV (and you do not see this Excel nor NotePad++), see e.g. https://stackoverflow.com/questions/22974765/weird-characters-added-to-first-column-name-after-reading-a-toad-exported-csv-fi?rq=1

so name "family" was read as "ï..family". This is fixed in read.csv() line.

2) The code was only working with a list that contains at least one case where there is subspecies or variant name! This obvious design mistake is now fixed so that the script works when input data contains just "pure" species names.

Regards, Lauri

1

Accepted answer

Dear Alex,

please try to update package data.table

This is probably caused by a bug in that package and it should be already fixed, see e.g. https://github.com/Rdatatable/data.table/issues/3495

Does this help?

Regards, Lauri

Dear Lauri,

thank you for your quick answer. Unfortunately, updating the data.table (+all) packages and R.Studio (v.1.3.1093) did not solve the problem. The error output stays the same, print(sp_dt)at this points yields:

family scientific_name 1: Chactidae auyantepuia amapaensis 2: Chactidae auyantepuia laurae


108: Chactidae vachoniochactas lasallei 109: Chactidae vachoniochactas roraima

The csv represents an extract of the final species list to be imported (from the GBIF DB) for testing purposes.

wexxo wexxo

Dear Alex, is comma the separator in your CSV input file? I noticed that this script fails if separator is tab or semicolon.. Indeed, it may needs fixes then.

Lauri (OF) Lauri (OF) ♦♦

Dear Lauri, Yes, the separator of the sp_list.csv is comma.

wexxo wexxo

Dear Alex, pls send a subset of your data to us and we can check this. Thanks! Lauri

Lauri (OF) Lauri (OF) ♦♦

Your answer

Markdown text. Shortcuts: Ctrl+B bold, Ctrl+I italic, Ctrl+K link, Ctrl+E code, Ctrl+Shift+V paste as plain text. Tab indents list items and code; press Escape, then Tab, to leave the text box.

Insert an image

Say what the image shows, for people who can't see it.

Keyboard shortcuts

Anywhere

?
Show this list
/
Search
g h
Go to the home page
g q
Go to the questions
g t
Go to the tags
g u
Go to the users
a
Ask a question

Lists of questions

j k
Next or previous question
Enter
Open the question

Question pages

j k
Next or previous post

Shortcuts never apply while you type in a text field. Members can turn them off in their preferences.