APLX Help : Help on APL language : System Functions & Variables : ⎕IMPORT Import data file
|
|||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
The monadic system function The right argument determines the name of the file to be read, and the format of the file. If the right argument is a character vector, it is interpreted as the name of the file you want to import (including full path if required) and the format of the file is inferred from the file extension. If the right argument is a two element nested vector, the first element is the filename (or full pathname), and the second is a text string specifying the file type. File types are case-insensitive. The explicit result is the converted data. For example, the two following statements are equivalent, and will import the contents of the file Budget2007.csv in 'comma-separated variables' ('CSV') format, into a variable called BUDGET in the workspace: BUDGET ← ⎕IMPORT 'Budget2007.csv'
BUDGET ← ⎕IMPORT 'Budget2007.csv' 'csv'
The following file formats are supported by
For example, suppose that the file 'Budget2007.csv' contains the following lines in CSV format: "","Q1","Q2","Q3","Q4" This can be read into a 4-row matrix of text vectors and numbers as follows: BUDGET ← ⎕IMPORT 'Budget2007.csv'
BUDGET
Q1 Q2 Q3 Q4
Sales 11300 13220 16550 19230
Expenses 12450 12950 13640 13980
Profit ¯1150 270 2910 5250
⎕DISPLAY BUDGET
┌→───────────────────────────────────┐
↓ ┌⊖┐ ┌→─┐ ┌→─┐ ┌→─┐ ┌→─┐ │
│ │ │ │Q1│ │Q2│ │Q3│ │Q4│ │
│ └─┘ └──┘ └──┘ └──┘ └──┘ │
│ ┌→────┐ │
│ │Sales│ 11300 13220 16550 19230 │
│ └─────┘ │
│ ┌→───────┐ │
│ │Expenses│ 12450 12950 13640 13980 │
│ └────────┘ │
│ ┌→─────┐ │
│ │Profit│ ¯1150 270 2910 5250 │
│ └──────┘ │
└∊───────────────────────────────────┘
ErrorsIf the file import fails because the format does not match what APLX is expecting, the error DATA DAMAGED will reported. In addition, a longer text message which gives more information will be displayed to the Session window (this is suppressed if error trapping is enabled). This example fails because the data is not in SYLK format: BUDGET ← ⎕IMPORT 'Budget2007.csv' 'slk'
Could not determine bounds of array
DATA DAMAGED
BUDGET←⎕IMPORT 'Budget2007.csv' 'slk'
^
Special considerations for Client-Server implementations of APLXIn Client-Server implementations of APLX, the front-end which implements the user-interface (the "Client") runs on one machine, and the APLX interpreter itself (the "Server") can run on a different machine. Typically, the Client will be the APLX front-end built as a 32-bit Windows application running on a desktop PC, and the Server will be a 64-bit APLX64 interpreter running on a 64-bit Linux or Windows server. In such systems, you can specify whether the file should be accessed on the Client or the Server machine. You do this by preceding the file name with either an Up Arrow |
|||||||||||||||||||||||||
APLX Help : Help on APL language : System Functions & Variables : ⎕IMPORT Import data file
|
|||||||||||||||||||||||||
Copyright © 1996-2010 MicroAPL Ltd