Git Product home page Git Product logo

ini's Introduction

ini

Travis-CI Build Status CRAN version CRAN downloads

Parse simple '.ini' configuration files to an structured list. Users can manipulate this resulting list with lapply() functions. This same structured list can be used to write back to file after modifications.

Installing

Development version

library(devtools)
install_github("dvdscripter/ini")

Prodution version

install.packages('ini')

Acknowledgments

  • SiBBr: first PoC was made to support another product

ini's People

Contributors

dvdscripter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

seakintruth

ini's Issues

Values without [section] should be read into "DEFAULT" one

Some INI files exist in the world where initial few variables have no [section]. This lib's read.ini currently would end up with error object 'lastSection' not found for those.

Simply adding lastSection <- "DEFAULT" atop of read func would solve that. I think mostly this approach would be ok to write.ini creating such section when asked but it would be cleaner if that section is written first without bracketed header.

Making both changes would help to work with basic key=value files without any sections too.

Many libs use "DEFAULT" for reading but writing implementation varies https://en.wikipedia.org/wiki/INI_file

Support for '=' at value

Report from below comes from e-mail. Writing here to document!

Create a new temp ini for reading

library(ini)
iniFile <- tempfile(fileext = '.ini')
sink(iniFile)
cat("; This line is a comment\n")
cat("# This one too!\n")
cat("[Hello World]\n")
cat("Foo1 = Bar=345 \n")
cat("Foo2 = Bar=345 \n")
cat("Foo3 = Bar\=345 \n")
sink()

Read ini

checkini <- read.ini(iniFile)

Check structure

checkini
checkini$Hello World$Foo1

#> Error: '=' is an unrecognized escape in character string starting ""Foo2 = Bar="

Space in INI File

When we call write.ini it adds space to the between key and value ,as a result if the ini file is parsed using INIParser in Java it would give error . if we add a space option like below it can be avoided

`write.ini <- function(x, filepath,spaceOption, encoding = getOption("encoding")) {

  con <- file(filepath, open = 'w', encoding = encoding)
  on.exit(close(con))

  for(section in names(x) ) {
    writeLines( paste0('[', section, ']'), con)
    for (key in x[ section ]) {
      if(spaceOption) {
        writeLines( paste0(names(key), ' = ', key), con)
      }else{
        writeLines( paste0(names(key), '=', key), con)
      }
     
    }
    writeLines("", con)
  }

}`

handling INI file without sections

Hello,

Thanks for this nice and straightforward package!

I'm wanting to parse an INI file generated by another tool and store any modifications afterwards. These files do not contain any sections, which read.ini (and I guess write.ini) don't really like.

The error in question is

Error in ini::read.ini("...") : 
  object 'lastSection' not found

Perhaps lastSection could be initialized with a default dummy value?

(I guess for now a workaround would be to manually inject a dummy section prior to parsing the file and do the writing with another function.)

Regards,
Rick

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.