read.opj: Parse Origin(R) project file into a list of objects

Description Usage Arguments Value Note Examples

View source: R/read.opj.R

Description

This function parses an OPJ file into a list of objects it consists of. Items understood by read.opj include spreadsheets, matrices, and notes.

Usage

1
  read.opj(file, encoding = 'latin1', tree = FALSE, ...)

Arguments

file

Path to the OPJ file to parse. Only file paths are supported, not R connections. Path is not expanded automatically.

encoding

Encoding of the strings inside the file being opened. This should correspond to the ANSI code page of Windows installation used to produce the file. The default of 'latin1' is usually safe to use. See iconvlist() for the full list of encodings supported by your R installation.

tree

Control the structure of the returned list. When FALSE (default), returned list is flat and its unique names correspond to the short names of the objects, while the comment attribute contains their long names and comments. When TRUE, the list itself becomes a recursive data structure containing the tree of the objects, making it possible to access objects by their paths in that tree.

...

The rest of the arguments is passed to as.data.frame when converting spreadsheets from lists of columns, making it possible to set stringsAsFactors and other parameters as needed.

Value

A named list containing objects stored in the file.

When tree = FALSE, the list is flat, its names are short names of the objects, and the comment attribute of the list contains the long names of the objects stored in the file.

When tree = TRUE, the list names are long names (if present; short otherwise) and the list itself represents the folder structure of the project.

Note

While Origin(R) and its scripting language seem to rely on the short names of the objects being unique across a project, neither long names nor folder names are guaranteed to avoid collisions. Tree-like lists returned by read.opj(..., tree = TRUE) might be easier to navigate interactively but present problems if someone gives multiple folders or objects the same long name.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
  x <- read.opj(system.file('test.opj', package = 'Ropj'))
  head(x$Book2, 7)
  comment(x$Book2)
  attr(x$Book2, 'commands')
  with(x$Book1, head(Sheet2 - Sheet1))
  x$MBook1$MSheet1[1:4,1:4]
  x$Note1

  ## Not run: 
    # encoding names aren't guaranteed to be supported across all platforms
    x <- read.opj(system.file('test.opj', package = 'Ropj'), 'WINDOWS-1251')
    x$cyrillic
  
## End(Not run)

  str(read.opj(system.file('tree.opj', package = 'Ropj'), tree = TRUE))

Example output

  A          B          C
1 1  0.4546487 123.000000
2 2 -0.3784012 456.000000
3 3 -0.1397077       this
4 4  0.4946791         is
5 5 -0.2720106          a
6 6 -0.2682865       text
7 7  0.4953037     column
[1] ""                               ""                              
[3] "long name\r\nunits\r\ncomments"
[1] "i"             "sin(i)*cos(i)" ""             
  A          B
1 0 -0.7720096
2 0  3.2921886
3 0  1.3915923
4 0  0.1679964
5 0  4.7539158
6 0  1.6966538
                 1 1.29032258064516 1.58064516129032 1.87096774193548
1                1                2                3                4
1.29032258064516 5                6                7                8
1.58064516129032 0                0                1                0
1.87096774193548 0                0                0                1
[1] "This is a note, written in friendly letters."
[1] "Эта заметка написана кириллицей в кодировке WINDOWS-1251."
List of 1
 $ tree:List of 1
  ..$ 1 bla bla bla text with spaces:List of 1
  .. ..$ 2:List of 2
  .. .. ..$ note: chr "Sorry Mario, but your note is in another folder!"
  .. .. ..$ 3   :List of 2
  .. .. .. ..$ 4: chr ""
  .. .. .. ..$ 4:List of 1
  .. .. .. .. ..$ 5:List of 1
  .. .. .. .. .. ..$ 6:List of 1
  .. .. .. .. .. .. ..$ 7 long name: chr "Here you go!"

Ropj documentation built on Aug. 2, 2021, 5:08 p.m.