Giter Club home page Giter Club logo

Comments (6)

earnaud avatar earnaud commented on July 29, 2024

A solution could be to use the try() function with different separators instead of a if() (l. 141).

from ediutils.

earnaud avatar earnaud commented on July 29, 2024

New idea:

detect_delimeter_earnaud <- function(data.file){
    require(data.table)
    delims = c(",","\t",";","|")
    # build a vector of logical answering the question:
    # 'For each of my delimiters, is it possible to read @data.file without error?'
    tries <- sapply(delims, # for each of my delimiters
                    function(delim) 
                        class(try( # is it possible
                            fread(input = data.file,sep = delim) # to read @data.file
                        ))!= "try-error" # without error ? (e.g. shall return object of class "list" for dataframes)
                    )
    
    if (is.null(delim.guess) || !any(tries)){ # not one of the tested values has been correct
        message(
            paste("I'm having trouble identifying the field delimeter of ", 
                  data.file, ". Enter the field delimeter of this file.",
                  ' Valid options are:  ,  \\t  ;  |', sep = ""))
        answer <- readline('ENTER here: ')
        if (answer == "\\t"){
            answer <- "\t"
        }
    } else {
        answer <- delim(tries)
    }
    return(answer)
}

from ediutils.

clnsmth avatar clnsmth commented on July 29, 2024

Thanks for this idea @earnaud. I'm curious, which field delimiter can't be detected by the current version of detect_delimeter()?

from ediutils.

earnaud avatar earnaud commented on July 29, 2024

Well, I am using ";" delimited CSV files but template_*() functions send me the error message from detect_delimiter(). The above chunk of code shall detect the separator of data.file.
Nota: I have not yet tested it.

from ediutils.

clnsmth avatar clnsmth commented on July 29, 2024

I may have solved this issue @earnaud. Please reinstall EDIutils and let me know if the issue persists. Thanks!

from ediutils.

earnaud avatar earnaud commented on July 29, 2024

After reinstalling and re-running my script, the issue doesnot reappear. Problem solved ! Thank you.

from ediutils.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.