Added license information to R source files.
[openmx:openmx.git] / R / MxFlatModel.R
1 #
2 #   Copyright 2007-2009 The OpenMx Project
3 #
4 #   Licensed under the Apache License, Version 2.0 (the "License");
5 #   you may not use this file except in compliance with the License.
6 #   You may obtain a copy of the License at
7
8 #        http://www.apache.org/licenses/LICENSE-2.0
9
10 #    Unless required by applicable law or agreed to in writing, software
11 #    distributed under the License is distributed on an "AS IS" BASIS,
12 #    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 #   See the License for the specific language governing permissions and
14 #   limitations under the License.
15
16
17 setClass(Class = "MxFlatModel",
18         representation = representation(
19                 objectives = "list",
20                 datasets = "list"
21         ),
22         contains = "MxModel")
23         
24 setMethod("initialize", "MxFlatModel",
25         function(.Object, model, objectives, datasets) {
26                 modelSlotNames <- slotNames(model)
27                 for(i in 1:length(modelSlotNames)) {
28                         name <- modelSlotNames[[i]]
29                         slot(.Object, name) <- slot(model, name)
30                 }
31                 .Object@objectives <- objectives
32                 .Object@datasets <- datasets
33                 return(.Object)
34         }
35 )       
36
37 omxGenerateDefinitionNames <- function(datasets) {
38         nameList <- lapply(datasets, 
39                 function(x) { dimnames(x)[[2]] })
40         result <- list()
41         if(length(nameList) > 0) {
42                 for(i in 1:length(nameList)) {
43                         colNames <- nameList[[i]]
44                         if(length(colNames) > 0) {
45                                 for(j in 1:length(colNames)) {
46                                         name <- colNames[[j]]
47                                         result[[name]] <- c(i - 1, j - 1)
48                                 }
49                         }       
50                 }
51         }
52         return(result)
53 }
54
55
56 setMethod("print", "MxFlatModel", function(x,...) {
57         callNextMethod()
58         cat("objectives : ")
59         print(x@objectives)
60         cat("datasets :", length(x@datasets), '\n') 
61 })
62
63 setMethod("show", "MxFlatModel", function(object) { 
64         callNextMethod()
65         cat("objectives : ")
66         print(object@objectives)
67         cat("datasets :", length(object@datasets), '\n') 
68 })