1

Ultimately, I want to use my yaml file in the ahp package. But first, I need to read my yaml file into R. I made my file in Notepad++ and everything is tab delineated.

I use the following code to try to read my file in R:

GIC <- yaml.load_file("/filepath/filename.yml") 

after loading the yaml library

I keep getting this error message:

Error in yaml.load(paste(readLines(input, encoding = "UTF-8"), collapse = "\n"), : Scanner error: while scanning for the next token at line 4, column 1found character that cannot start any token at line 4, column 1 In addition: Warning message: In readLines(input, encoding = "UTF-8") : incomplete final line found on 'GIC assessment.yml'

When I make it space-delineated instead, I get this error message:

Warning message: In readLines(input, encoding = "UTF-8") :
incomplete final line found on 'GIC assessment 2.yml'

I have actually tried with a yaml file that I know specifically works in R (the data package from ahp) and it also gives me above error message.

I am at a complete loss, any ideas would be greatly appreciated.

My file is: Version: 1.0

Alternatives: &alternatives
    GIC Monitoring:
    Geologic Data:
    USGS:
    Energy Infrastructure:
    Variometer:
Goal:
    name: Data Source
    preferences:
        pairwise:
            - [Coverage, Cost, 2]
            - [Coverage, Reliability, 1/3]
            - [Cost, Reliability, 1/5]
    children:
        Coverage:
            preferences:
                pairwise:
                    - [Temporal, Spatial, 1/5]
            children:
                Temporal:
                    preferences:
                        pairwise:
                            - [GIC Monitoring, Geologic Data, 8]
                            - [GIC Monitoring, USGS, 8]
                            - [GIC Monitoring, Energy Infrastructure, 8]
                            - [GIC Monitoring, Variometer, 9]
                            - [Geologic Data, USGS, 1]
                            - [Geologic Data, Energy Infrastructure, 1]
                            - [Geologic Data, Variometer, 7]
                            - [USGS, Energy Infrastructure, 1]
                            - [USGS, Variometer, 7]
                            - [Energy Infrastructure, Variometer, 7]
                Spatial:
                    preferences:
                        pairwise:
                            - [GIC Monitoring, Geologic Data, 1]
                            - [GIC Monitoring, USGS, 1]
                            - [GIC Monitoring, Energy Infrastructure, 1/7]
                            - [GIC Monitoring, Variometer, 5]
                            - [Geologic Data, USGS, 1]
                            - [Geologic Data, Energy Infrastructure, 1/7]
                            - [Geologic Data, Variometer, 5]
                            - [USGS, Energy Infrastructure, 1/7]
                            - [USGS, Variometer, 5]
                            - [Energy Infrastructure, Variometer, 5]
            children: *alternatives
        Cost:
            preferences:
                pairwise:
                    - [GIC Monitoring, Geologic Data, 1]
                    - [GIC Monitoring, USGS, 1]
                    - [GIC Monitoring, Energy Infrastructure, 1]
                    - [GIC Monitoring, Variometer, 1/9]
                    - [Geologic Data, USGS, 1]
                    - [Geologic Data, Energy Infrastructure, 1]
                    - [Geologic Data, Variometer, 1/9]
                    - [USGS, Energy Infrastructure, 1]
                    - [USGS, Variometer, 1/9]
                    - [Energy Infrastructure, Variometer, 1/9]
            children: *alternatives
        Reliability:
            preferences:
                pairwise:
                    - [GIC Monitoring, Geologic Data, 1]
                    - [GIC Monitoring, USGS, 1]
                    - [GIC Monitoring, Energy Infrastructure, 1]
                    - [GIC Monitoring, Variometer, 9]
                    - [Geologic Data, USGS, 1]
                    - [Geologic Data, Energy Infrastructure, 1]
                    - [Geologic Data, Variometer, 9]
                    - [USGS, Energy Infrastructure, 1]
                    - [USGS, Variometer, 9]
                    - [Energy Infrastructure, Variometer, 9]
            children: *alternatives
Martin Schmelzer
  • 23,283
  • 6
  • 73
  • 98
Shirley
  • 127
  • 2
  • 8
  • 2
    "incomplete final line": you need a newline at the end of the file ; although, you'll have a " Duplicate map key: 'children'" because of line 46 (which you should rename/move elsewhere) – scoa Dec 01 '16 at 17:58
  • 1
    Possible duplicate of ['Incomplete final line' warning when trying to read a .csv file into R](http://stackoverflow.com/questions/5990654/incomplete-final-line-warning-when-trying-to-read-a-csv-file-into-r) – scoa Dec 01 '16 at 18:00
  • 2
    The YAML documentation clearly states [To maintain portability, tab characters must not be used in indentation, since different systems treat tabs differently.](http://yaml.org/spec/1.2/spec.html#id2777534) so why ignore that and use tab deliniation? – Anthon Dec 02 '16 at 07:09
  • 1
    Note that YAML does not require a newline at the end of the file, and if R's implementation does, that's a bug and should be reported. – flyx Dec 02 '16 at 09:37
  • Other thing to note is that newline should set the next line cursor at the beginning. ie. if the last `key:value` has indentation, last line shouldn't. – close2zero May 17 '23 at 15:41

0 Answers0