UNPKG

@georgestagg/webr

Version:

The statistical programming langauge R compiled into WASM for use in a web browser and node.

317 lines (316 loc) 11.2 kB
import type { RProxy } from './proxy'; export interface ToTreeOptions { depth: number; } export declare type RObject = RProxy<RObjImpl>; export declare type RNull = RProxy<RObjNull>; export declare type RSymbol = RProxy<RObjSymbol>; export declare type RPairlist = RProxy<RObjPairlist>; export declare type REnvironment = RProxy<RObjEnvironment>; export declare type RString = RProxy<RObjString>; export declare type RLogical = RProxy<RObjLogical>; export declare type RInteger = RProxy<RObjInteger>; export declare type RDouble = RProxy<RObjDouble>; export declare type RComplex = RProxy<RObjComplex>; export declare type RCharacter = RProxy<RObjCharacter>; export declare type RList = RProxy<RObjList>; export declare type RRaw = RProxy<RObjRaw>; export declare type RFunction = RProxy<RObjFunction> & ((...args: unknown[]) => Promise<unknown>); export declare type RPtr = number; export declare const RTypeMap: { readonly null: 0; readonly symbol: 1; readonly pairlist: 2; readonly closure: 3; readonly environment: 4; readonly promise: 5; readonly call: 6; readonly special: 7; readonly builtin: 8; readonly string: 9; readonly logical: 10; readonly integer: 13; readonly double: 14; readonly complex: 15; readonly character: 16; readonly dots: 17; readonly any: 18; readonly list: 19; readonly expression: 20; readonly bytecode: 21; readonly pointer: 22; readonly weakref: 23; readonly raw: 24; readonly s4: 25; readonly new: 30; readonly free: 31; readonly function: 99; }; export declare type RType = keyof typeof RTypeMap; export declare type RTypeNumber = typeof RTypeMap[keyof typeof RTypeMap]; export declare type RTargetRaw = { obj: RawType; targetType: 'raw'; }; export declare type RTargetPtr = { obj: { type?: RType; ptr: RPtr; methods?: string[]; }; targetType: 'ptr'; }; export declare type RTargetError = { obj: { message: string; name: string; stack?: string; }; targetType: 'err'; }; export declare type RTargetType = 'raw' | 'ptr' | 'err'; export declare type RTargetObj = RTargetRaw | RTargetPtr | RTargetError; declare type Nullable<T> = T | RObjNull; declare type Complex = { re: number; im: number; }; export declare type RawType = number | string | boolean | undefined | null | Complex | Error | ArrayBuffer | ArrayBufferView | Array<RawType> | Map<RawType, RawType> | Set<RawType> | { [key: string]: RawType; }; export declare type NamedEntries<T> = [string | null, T][]; export declare type NamedObject<T> = { [key: string]: T; }; export declare type RObjData = RObjImpl | RawType | RObjectTree<RObjImpl>; export declare type RObjAtomicData<T> = T | (T | null)[] | RObjectTreeAtomic<T>; export declare type RObjectTree<T> = RObjectTreeImpl<(RObjectTree<T> | RawType | T)[]>; export declare type RObjectTreeAtomic<T> = RObjectTreeImpl<(T | null)[]>; declare type RObjectTreeImpl<T> = { type: RType; names: (string | null)[] | null; values: T; missing?: boolean[]; }; export declare class RObjImpl { ptr: RPtr; constructor(target: RTargetObj | RawType); get [Symbol.toStringTag](): string; type(): RType; protect(): void; unprotect(): void; preserve(): void; release(): void; isNull(): this is RObjNull; isUnbound(): boolean; attrs(): Nullable<RObjPairlist>; setNames(values: (string | null)[] | null): this; names(): (string | null)[] | null; includes(name: string): boolean | null; toTree(options?: ToTreeOptions, depth?: number): RawType | RObjectTree<RObjImpl>; toJs(): ReturnType<this["toTree"]>; subset(prop: number | string): RObjImpl; get(prop: number | string): RObjImpl; getDollar(prop: string): RObjImpl; pluck(...path: (string | number)[]): RObjImpl | undefined; set(prop: string | number, value: RObjImpl | RawType): RObjImpl; static getMethods(obj: RObjImpl): string[]; static get globalEnv(): RObjImpl; static get emptyEnv(): RObjImpl; static get baseEnv(): RObjImpl; static get null(): RObjNull; static get naLogical(): number; static get naInteger(): number; static get naDouble(): number; static get naString(): RObjImpl; static get unboundValue(): RObjImpl; static get bracketSymbol(): RObjSymbol; static get bracket2Symbol(): RObjSymbol; static get dollarSymbol(): RObjSymbol; static get namesSymbol(): RObjSymbol; static wrap(ptr: RPtr): RObjImpl; static protect<T extends RObjImpl>(obj: T): T; static unprotect(n: number): void; static unprotectPtr(obj: RObjImpl): void; static preserveObject(obj: RObjImpl): void; static releaseObject(obj: RObjImpl): void; } export declare class RObjNull extends RObjImpl { constructor(); toTree(): { type: 'null'; }; } export declare class RObjSymbol extends RObjImpl { toTree(): RawType; toObject(): { printname: string | null; symvalue: RPtr | null; internal: RPtr | null; }; printname(): RObjString; symvalue(): RObjImpl; internal(): RObjImpl; } export declare class RObjPairlist extends RObjImpl { constructor(val: RawType | (RawType | null)[] | RTargetPtr | RObjectTree<RTargetObj>); get length(): number; toArray(options?: ToTreeOptions): RObjData[]; toObject({ allowDuplicateKey, allowEmptyKey, depth, }?: { allowDuplicateKey?: boolean | undefined; allowEmptyKey?: boolean | undefined; depth?: number | undefined; }): NamedObject<RObjData>; entries(options?: ToTreeOptions): NamedEntries<RObjData>; toTree(options?: ToTreeOptions, depth?: number): RObjectTree<RObjImpl>; includes(name: string): boolean; setcar(obj: RObjImpl): void; car(): RObjImpl; cdr(): Nullable<RObjPairlist>; tag(): Nullable<RObjSymbol>; } export declare class RObjList extends RObjImpl { constructor(val: RawType | (RawType | null)[] | RTargetPtr | RObjectTree<RTargetObj>); get length(): number; toArray(options?: { depth: number; }): RObjData[]; toObject({ allowDuplicateKey, allowEmptyKey, depth, }?: { allowDuplicateKey?: boolean | undefined; allowEmptyKey?: boolean | undefined; depth?: number | undefined; }): NamedObject<RObjData>; entries(options?: { depth: number; }): NamedEntries<RObjData>; toTree(options?: { depth: number; }, depth?: number): RObjectTree<RObjImpl>; } export declare class RObjFunction extends RObjImpl { exec(...args: (RawType | RObjImpl)[]): RObjImpl; } export declare class RObjString extends RObjImpl { toString(): string; toTree(): string; } export declare class RObjEnvironment extends RObjImpl { constructor(val: RTargetPtr | RObjectTree<RTargetObj>); ls(all?: boolean, sorted?: boolean): string[]; bind(name: string, value: RObjImpl | RawType): void; names(): string[]; frame(): RObjImpl; subset(prop: number | string): RObjImpl; toObject({ depth }?: { depth?: number | undefined; }): NamedObject<RawType | RObjImpl | RObjectTree<RObjImpl>>; toTree(options?: { depth: number; }, depth?: number): RObjectTree<RObjImpl>; } declare type TypedArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array; declare type atomicType = number | boolean | Complex | string; declare abstract class RObjAtomicVector<T extends atomicType> extends RObjImpl { get length(): number; get(prop: number | string): this; subset(prop: number | string): this; getDollar(prop: string): RObjImpl; detectMissing(): boolean[]; abstract toTypedArray(): TypedArray; toArray(): (T | null)[]; toObject({ allowDuplicateKey, allowEmptyKey }?: { allowDuplicateKey?: boolean | undefined; allowEmptyKey?: boolean | undefined; }): NamedObject<T | null>; entries(): NamedEntries<T | null>; toTree(): RObjectTreeAtomic<T>; } export declare class RObjLogical extends RObjAtomicVector<boolean> { constructor(val: RTargetObj | RObjAtomicData<boolean>); getLogical(idx: number): boolean | null; toLogical(): boolean | null; toTypedArray(): Int32Array; toArray(): (boolean | null)[]; } export declare class RObjInteger extends RObjAtomicVector<number> { constructor(val: RTargetObj | RObjAtomicData<number>); getNumber(idx: number): number | null; toNumber(): number | null; toTypedArray(): Int32Array; } export declare class RObjDouble extends RObjAtomicVector<number> { constructor(val: RTargetObj | RObjAtomicData<number>); getNumber(idx: number): number | null; toNumber(): number | null; toTypedArray(): Float64Array; } export declare class RObjComplex extends RObjAtomicVector<Complex> { constructor(val: RTargetObj | RObjAtomicData<Complex>); getComplex(idx: number): Complex | null; toComplex(): Complex | null; toTypedArray(): Float64Array; toArray(): (Complex | null)[]; } export declare class RObjCharacter extends RObjAtomicVector<string> { constructor(val: RTargetObj | RObjAtomicData<string>); getString(idx: number): string | null; toString(): string | null; toTypedArray(): Uint32Array; toArray(): (string | null)[]; } export declare class RObjRaw extends RObjAtomicVector<number> { constructor(val: RTargetObj | RObjAtomicData<number>); getNumber(idx: number): number | null; toNumber(): number | null; toTypedArray(): Uint8Array; } /** * Test for an RObjImpl instance * * RObjImpl is the internal interface to R objects, intended to be used * on the worker thread. * * @private * @param {any} value The object to test. * @return {boolean} True if the object is an instance of an RObjImpl. */ export declare function isRObjImpl(value: any): value is RObjImpl; /** * Test for an RObject instance * * RObject is the user facing interface to R objects. * * @param {any} value The object to test. * @return {boolean} True if the object is an instance of an RObject. */ export declare function isRObject(value: any): value is RObject; /** * Test for an RTargetObj object * * @param {any} value The object to test. * @return {boolean} True if the object is an instance of an RTargetObj. */ export declare function isRTargetObj(value: any): value is RTargetObj; /** * Test for an RTargetPtr instance * * @param {any} value The object to test. * @return {boolean} True if the object is an instance of an RTargetPtr. */ export declare function isRTargetPtr(value: any): value is RTargetPtr; /** * Test for an RFunction instance * * @param {any} value The object to test. * @return {boolean} True if the object is an instance of an RFunction. */ export declare function isRFunction(value: any): value is RFunction; /** * Test for an RObjectTree instance * * @param {any} value The object to test. * @return {boolean} True if the object is an instance of an RObjectTree. */ export declare function isRObjectTree(value: any): value is RObjectTree<any>; export declare function getRObjClass(type: RTypeNumber): typeof RObjImpl; export {};