{"category":{"__v":2,"_id":"566e55c12c1e760d0030c56d","pages":["566e55c12c1e760d0030c56e","566e55c12c1e760d0030c56f","566e55c12c1e760d0030c570","566e55c12c1e760d0030c571","566e55c12c1e760d0030c572","566e55c12c1e760d0030c573","566e55c12c1e760d0030c574","566e55c12c1e760d0030c575","566e55c12c1e760d0030c576","566e55c12c1e760d0030c577","566e55c12c1e760d0030c578","566e55c12c1e760d0030c579","566e55c12c1e760d0030c57a","566e55c12c1e760d0030c57b","566e55c12c1e760d0030c57c","566e55c12c1e760d0030c57d","566e55c12c1e760d0030c57e","566e55c12c1e760d0030c57f","566e55c12c1e760d0030c580","566e55c12c1e760d0030c581","566e55c12c1e760d0030c582","566e55c12c1e760d0030c583","566e55c12c1e760d0030c584","566e55c12c1e760d0030c585","566e55c12c1e760d0030c586","566e55c12c1e760d0030c587","566e55c12c1e760d0030c588","566e5640c15c8f0d000ee863"],"project":"54408e54309354080070a896","version":"566e55c02c1e760d0030c56c","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-10-17T03:34:44.886Z","from_sync":false,"order":0,"slug":"documentation","title":"Documentation"},"project":"54408e54309354080070a896","user":"544083bee239230800071bef","version":{"__v":1,"_id":"566e55c02c1e760d0030c56c","project":"54408e54309354080070a896","createdAt":"2015-12-14T05:38:08.400Z","releaseDate":"2015-12-14T05:38:08.400Z","categories":["566e55c12c1e760d0030c56d"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.2.3","version":"1.2.3"},"_id":"566e55c12c1e760d0030c576","__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-05-11T22:36:06.419Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":8,"body":"# Introduction\nSimilar to C, Julia types can contain sub components (fields) and and in that case are considered struct types which can be mapped to Javascript objects.  Thus, new to version 1.1 a mapping has been established where if a [JRef](doc:jref) is created which corresponds to a Julia struct type, it will have a [Javascript Accessor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors) defined for each field of the struct type.  Currently these values are read only.\n\n# DataFrames example\n\nFollowing the [DataFrame Introduction](http://dataframesjl.readthedocs.org/en/latest/getting_started.html), a DataFrame can be created and then introspected using the following:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var julia = require('node-julia');\\nvar DataFrames = julia.import('DataFrames');\\n\\nvar dv = julia.eval('DataFrames.:::at:::data([NA, 3, 2, 5, 4, NA, NA, 6, 7])');\\n\\nconsole.log(JSON.stringify(dv,null,2));\\nconsole.log('mean of dv with NA values dropped: ' + julia.exec('mean',DataFrames.dropna(dv)));\\n\\ndv.data[1] = 1;\\nconsole.log('dv.data is readonly, so dv.data[1] remains set to ' + dv.data[1]);\\n\\nfor(var i = 0;i < dv.na.len;i++) {\\n   if(i % 64 == 0) chunk = dv.na.chunks[i/64];\\n\\n   // Use DataFrames builtin isna; Julia indexing is 1 based not 0 like Javascript\\n   var na = DataFrames.isna(julia.exec('getindex',dv,i + 1));  \\n\\n   // Compare\\n   if((chunk >> i%64) & 1) console.log('index ' + i + ' is NA (Julia = ' + na + ')');\\n   else console.log('index ' + i + ' is not NA (Julia = ' + na + ')');\\n}\\n\",\n      \"language\": \"javascript\",\n      \"name\": \"DataFrameIntrospect.js\"\n    }\n  ]\n}\n[/block]\n## Output\n\n    {\n      \"data\": {\n        \"0\": 3,\n        \"1\": 3,\n        \"2\": 2,\n        \"3\": 5,\n        \"4\": 4,\n        \"5\": 3,\n        \"6\": 3,\n        \"7\": 6,\n        \"8\": 7\n      },\n      \"na\": {\n        \"chunks\": {\n          \"0\": 97\n        },\n        \"len\": 9\n      }\n    }\n    mean of dv with NA values dropped: 4.5\n    dv.data is readonly, so dv.data[1] remains set to 3\n    index 0 is NA (Julia = true)\n    index 1 is not NA (Julia = false)\n    index 2 is not NA (Julia = false)\n    index 3 is not NA (Julia = false)\n    index 4 is not NA (Julia = false)\n    index 5 is NA (Julia = true)\n    index 6 is NA (Julia = true)\n    index 7 is not NA (Julia = false)\n    index 8 is not NA (Julia = false)\n    \n### Explanation\nThere are several things going on here.  The DataFrame package is [Imported](doc:import), and a [DataArray](https://github.com/JuliaStats/DataArrays.jl/blob/master/src/dataarray.jl) is created using the `@data` macro using `julia.eval`, the resulting **JRef** is printed, `DataFrames.dropna` is used to remove the NA values, and the mean is calculated on the result.  The **na** component of a *DataArray* is a *BitArray{1}* and so to check the validity of each index, the correct bit of the correct chunk is examined.  In this case **na** is of length 9, so there is only 1 chunk; all of this is hidden by the Julia type BitArray, but is exposed in Javascript.","excerpt":"","slug":"struct-type-introspection","type":"basic","title":"Struct Type Introspection"}

Struct Type Introspection


# Introduction Similar to C, Julia types can contain sub components (fields) and and in that case are considered struct types which can be mapped to Javascript objects. Thus, new to version 1.1 a mapping has been established where if a [JRef](doc:jref) is created which corresponds to a Julia struct type, it will have a [Javascript Accessor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors) defined for each field of the struct type. Currently these values are read only. # DataFrames example Following the [DataFrame Introduction](http://dataframesjl.readthedocs.org/en/latest/getting_started.html), a DataFrame can be created and then introspected using the following: [block:code] { "codes": [ { "code": "var julia = require('node-julia');\nvar DataFrames = julia.import('DataFrames');\n\nvar dv = julia.eval('DataFrames.@data([NA, 3, 2, 5, 4, NA, NA, 6, 7])');\n\nconsole.log(JSON.stringify(dv,null,2));\nconsole.log('mean of dv with NA values dropped: ' + julia.exec('mean',DataFrames.dropna(dv)));\n\ndv.data[1] = 1;\nconsole.log('dv.data is readonly, so dv.data[1] remains set to ' + dv.data[1]);\n\nfor(var i = 0;i < dv.na.len;i++) {\n if(i % 64 == 0) chunk = dv.na.chunks[i/64];\n\n // Use DataFrames builtin isna; Julia indexing is 1 based not 0 like Javascript\n var na = DataFrames.isna(julia.exec('getindex',dv,i + 1)); \n\n // Compare\n if((chunk >> i%64) & 1) console.log('index ' + i + ' is NA (Julia = ' + na + ')');\n else console.log('index ' + i + ' is not NA (Julia = ' + na + ')');\n}\n", "language": "javascript", "name": "DataFrameIntrospect.js" } ] } [/block] ## Output { "data": { "0": 3, "1": 3, "2": 2, "3": 5, "4": 4, "5": 3, "6": 3, "7": 6, "8": 7 }, "na": { "chunks": { "0": 97 }, "len": 9 } } mean of dv with NA values dropped: 4.5 dv.data is readonly, so dv.data[1] remains set to 3 index 0 is NA (Julia = true) index 1 is not NA (Julia = false) index 2 is not NA (Julia = false) index 3 is not NA (Julia = false) index 4 is not NA (Julia = false) index 5 is NA (Julia = true) index 6 is NA (Julia = true) index 7 is not NA (Julia = false) index 8 is not NA (Julia = false) ### Explanation There are several things going on here. The DataFrame package is [Imported](doc:import), and a [DataArray](https://github.com/JuliaStats/DataArrays.jl/blob/master/src/dataarray.jl) is created using the `@data` macro using `julia.eval`, the resulting **JRef** is printed, `DataFrames.dropna` is used to remove the NA values, and the mean is calculated on the result. The **na** component of a *DataArray* is a *BitArray{1}* and so to check the validity of each index, the correct bit of the correct chunk is examined. In this case **na** is of length 9, so there is only 1 chunk; all of this is hidden by the Julia type BitArray, but is exposed in Javascript.