---
title: "Problems with R script to prepare species lists for Collect"
url: "https://openforis.support/questions/2976/problems-with-r-script-to-prepare-species-lists-for-collect"
tags: ["collect", "calc"]
status: "accepted"
score: 0
answer_count: 2
asked: "2020-12-10T12:00:41"
last_activity: "2020-12-11T14:42:19"
source: "Open Foris Support - Q&A Forum"
license: "Copyright Open Foris, 2021. Some rights reserved under creative commons license."
---

# Problems with R script to prepare species lists for Collect

Asked by wexxo on 2020-12-10

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


## Accepted answer (score 1, by Lauri (OF) on 2020-12-11)

Link: https://openforis.support/questions/2976/problems-with-r-script-to-prepare-species-lists-for-collect/2992

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][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]: https://stackoverflow.com/questions/22974765/weird-characters-added-to-first-column-name-after-reading-a-toad-exported-csv-fi?rq=1


## Answer (score 1, by Lauri (OF) on 2020-12-10)

Link: https://openforis.support/questions/2976/problems-with-r-script-to-prepare-species-lists-for-collect/2980

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)
> 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))
> Dear Lauri, Yes, the separator of the sp_list.csv is comma. (wexxo)
> Dear Alex, pls send a subset of your data to us and we can check this. Thanks! Lauri (Lauri (OF))
